nginx redirect all http to https with exceptions nginx redirect all http to https with exceptions nginx nginx

nginx redirect all http to https with exceptions


Nginx finds the longest matching location and processes it first, but your return at the end of the server block was being processed regardless. This will redirect everything but /exception/ which is passed upstream.

server {     listen 127.0.0.1:80;    access_log off;    location / {        return 301 https://localhost$request_uri;     }    location /exception/ {        proxy_pass http://127.0.0.1:7080;        proxy_set_header Host             $host;        proxy_set_header X-Real-IP        $remote_addr;        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;        proxy_set_header X-Accel-Internal /internal-nginx-static-location;    }    }