🚂 nginx - HTTP to HTTPS to Port
Updated at 2015-07-28 00:13
# As root:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443
# nginx server configuration at /etc/nginx/site-available/example.com
server {
listen 8080;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 8443 ssl;
server_name example.com;
access_log /var/log/nginx/example.log;
ssl_certificate /path/to/example.com.crt;
ssl_certificate_key /path/to/example.com.key;
location / {
proxy_pass http://127.0.0.1:3000/; # Change process port.
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}