How To Route SSL Traffic With Nginx

This is the code in /etc/nginx/conf.d/default.conf:

server {
 listen 443;
 ssl on;
 ssl_certificate /var/lib/lxc/lxc_container/rootfs/etc/apache2/cert.crt;
 ssl_certificate_key /var/lib/lxc/lxc_container/rootfs/etc/apache2/cert.key;

location / {
 proxy_set_header X-Forwarded-Proto https;
 add_header Front-End-Https on;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header Host $host;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_buffering off;
 proxy_redirect off;


Note: nginx (on the main host) is using same ssl certificate as apache on the lxc container.

server {
 listen 80;
 return 301$request_uri;

This dirrective redirects the http traffic to https.

Leave a Comment