简体   繁体   English

Nginx HTTP到HTTPS重定向循环

[英]Nginx HTTP to HTTPS redirect loop

I have the folloiwng Nginx configuration: 我有以下Nginx配置:

server {
        listen 80;
        server_name .example.net .example.com;
        return 301 https://example.com$request_uri;
}

server {
        listen 80;
        server_name beta.example.com;

        error_page 403 /403;
        error_page 404 /404;
        error_page 500 /500;

        client_max_body_size 5M;

        # Handle all locations
        location / {
                proxy_pass http://127.0.0.1:8080;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

server {
        listen 443;
        ssl on;
        ssl_certificate /etc/ssl/cert_chain.crt;
        ssl_certificate_key /etc/ssl/csr.pem;

        server_name example.com;

        error_page 403 /403;
        error_page 404 /404;
        error_page 500 /500;

        client_max_body_size 5M;

        location / {
          proxy_pass http://127.0.0.1:8000;

          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

I'm wanting to redirect HTTP requests to HTTPS however I get a redirect loop. 我想将HTTP请求重定向到HTTPS,但是出现重定向循环。 I've read other answers on different questions including this one and this one however none of their solutions solved mine. 我已经阅读了有关不同问题的其他答案,包括这个问题和这个问题,但是他们的解决方案都无法解决我的问题。 Any ideas? 有任何想法吗? Thanks. 谢谢。

It seems like your backend (running on 127.0.0.1:8000) issues Location: http://example.com/ header. 您的后端(在127.0.0.1:8000上运行)似乎出现问题Location: http://example.com/标头。

Please look into the access logs, nginx's and backend's too. 请同时查看访问日志,nginx和后端。

Or use httpliveheaders or tcpdump to investigate the traffic. 或使用httpliveheaderstcpdump调查流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM