How to redirect on the same port from http to https with nginx reverse proxy

后端 未结 5 1884
借酒劲吻你
借酒劲吻你 2020-12-24 01:12

I use reverse proxy with Nginx and I want to force the request into HTTPS, so if a user wants to access the url with http, he will be automatically redirected to HTTPS.

5条回答
  •  情书的邮戳
    2020-12-24 02:10

    Found something that is working well :

    server {
            listen 8001  ssl;
            ssl_certificate /home/xxx/server.crt;
            ssl_certificate_key /home/xxx/server.key;
            error_page 497 301 =307 https://$host:$server_port$request_uri;
            location /{
                proxy_pass http://localhost:8000;
                proxy_redirect off;
                proxy_set_header Host $host:$server_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Ssl on;
            }
    }
    

提交回复
热议问题