【问题标题】:nginx redirect proxy requests http to https get to many redirections messagenginx 重定向代理请求 http 到 https 得到太多重定向消息
【发布时间】:2018-11-27 17:45:07
【问题描述】:

在我的 nginx 服务器中,我会将所有 http 传入请求重定向到 https。 我使用 gunicorn 并将代理设置为 / 位置 127.0.0.1:8080 我的 nginx.conf 配置文件的一部分是:

server {
    listen       80;
    listen       443 default ssl http2;
    ssl_certificate  /var/www/web/core/mycert.crt;
    ssl_certificate_key  /var/www/web/core/mykey.key;
    server_name  ~^(?<subdomain>\w+)\.mydomain\.io$;
    root         /var/www;


    return 301 https://$server_name$request_uri;


    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location /static/ {
    alias /var/www/web/core/frontend/static/;
    }       

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        #add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
        proxy_set_header  X-DTS-SCHEMA $subdomain;
    }

但是当我尝试打开我的页面的 http 版本时,我得到“错误到许多重定向” 我还尝试添加我的代理指令:

proxy_redirect http:// https://;

但什么也没发生。

如何每次都将我的代理请求重定向到 https?

提前致谢

【问题讨论】:

    标签: nginx https gunicorn


    【解决方案1】:

    你的代码有一个很大的错误,你不能像以前那样做:

    return 301 https://$server_name$request_uri;
    

    如果你想这样使用,你应该拆分 http 和 https 服务器。当你阅读你的文件时,你只是在每次到达虚拟主机时重定向,这导致了太多的重定向。

    如果您已经在 https 中,您还可以在 return 上设置一个不执行的条件...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-22
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多