nginx SSL重定向不起作用

时间:2018-06-22 04:07:42

标签: express nginx

我已将nginx配置为将流量转发到快速服务器,并希望通过将直接将http://的流量重定向到https://来强制使用SSL。我已经在该主题上进行了广泛的搜索,但是无法使其正常工作。 HTTPS正常运行,但是HTTP正常运行-重定向似乎没有任何效果。

server {
    listen 80;
    listen [::]:80;
    server_name my.domain www.my.domain;
    return 301 https://my.domain$request_uri;
}
server {

    listen 443 ssl default_server;
    listen [::]:443 ssl;
    server_name my.domain www.my.domain;

    ssl_certificate     /home/user/my_domain.crt;
    ssl_certificate_key /home/user/my_domain.key;


    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    access_log            /var/log/nginx/mydomain.access.log;

    location / {

      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-Forwarded-Proto $scheme;

      proxy_pass          https://localhost:3000;
      proxy_read_timeout  90;

      proxy_redirect      https://localhost:3000 https://my.domain;
    }

}

0 个答案:

没有答案