Skip to content

Instantly share code, notes, and snippets.

@phackwer
Last active April 18, 2018 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phackwer/f5dd76647781ab96f9f750fdffb543f6 to your computer and use it in GitHub Desktop.
Save phackwer/f5dd76647781ab96f9f750fdffb543f6 to your computer and use it in GitHub Desktop.
Rancher with SSL
0 - Install supported version of docker and docker compose (in docker hosts too)
apt-get remove docker*
curl https://releases.rancher.com/install-docker/17.03.sh | sh
sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
1 - Start your Rancher instance, locked for the outside world:
docker run -d --restart=unless-stopped --name rancher-server -p 0.0.0.0:8080:8080 rancher/server:stable
2 - Install nginx
apt-get install nginx
3 - Create the folder /etc/nginx/ssl_certs/ and place your SSL certificates for HTTPS there
4 - Remove the default setup for nginx:
rm /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
5 - Create this file in your server at /etc/nginx/sites-available/rancher, to be used by the nginx proxy, to make all traffic go through HTTPS:
map $http_upgrade $connection_upgrade {
default Upgrade;
'' close;
}
server {
listen 443 ssl;
server_name racher.DOMAIN.com;
ssl_certificate /etc/nginx/ssl_certs/DOMAIN.com.crt;
ssl_certificate_key /etc/nginx/ssl_certs/DOMAIN.com.key;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# This allows the ability for the execute shell window to remain open for up to 15 minutes. Without this parameter, the default is 1 minute and will automatically close.
proxy_read_timeout 900s;
}
}
server {
listen 80;
server_name racher.DOMAIN.com;
return 301 https://$server_name$request_uri;
}
6 - Create the symlinks in the server
ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/
7 - Remember to allow access to ports 80 and 443 on your server to have Rancher running in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment