设置SSL后,Ngnix配置将HTTPS重定向到HTTP

时间:2016-09-13 14:45:42

标签: ssl nginx https

这是我的网站的Nginx配置。我最近编辑了它以设置我的SSL证书并仅从HTTPS提供服务。现在,HTTP工作/打开正常,但HTTPS重定向到HTTP

server {
    listen 80;
    listen 443 ssl;
    server_name abc.test.com;

    add_header Strict-Transport-Security "max-age=31536000";

    ssl_certificate /etc/nginx/ssl/nginx.pem;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    client_max_body_size 10M;

    location / {
            proxy_pass http://localhost:2368/;
            proxy_redirect off;
            proxy_set_header HOST $host;
            proxy_buffering off;
    }
}

域名被替换为示例以保持简单。

尝试删除听80;但没有帮助。

1 个答案:

答案 0 :(得分:2)

你能试试吗?它将HTTP站点重定向到HTTPS。

   server {
            listen 80;
            listen [::]:80;

            server_name abc.test.com;

            return 301 https://$host$request_uri;
    }

    server {
            # SSL configuration
            listen 443 ssl;
            listen [::]:443 ssl;
            server_name abc.test.com;

            ssl_certificate /etc/nginx/ssl/nginx.pem;
            ssl_certificate_key /etc/nginx/ssl/nginx.key;

            add_header Strict-Transport-Security "max-age=31536000";

            client_max_body_size 10M;

            location / {
               proxy_pass http://localhost:2368/;
               proxy_redirect off;
               proxy_set_header HOST $host;
               proxy_buffering off;
            }
    }