繁体   English   中英

同时使用HTTP和HTTPS设置Ghost + Nginx时出现ERR_TOO_MANY_REDIRECTS

[英]ERR_TOO_MANY_REDIRECTS while setting up Ghost + Nginx with both HTTP and HTTPS

我正在使用Nginx(1.8.1)在VPS中部署Ghost(0.7.6)。 为了确保仪表板和登录页面的安全,在访问此类页面(例如/ghost页面)时,我强制所有请求使用HTTPS。 但是,对于对其他任何页面的任何请求(例如访问Ghost博客本身),我想强制其使用HTTP。 Ghost正在收听127.0.0.1:2368

奇怪的是,结果并没有达到我的预期:每次访问博客(例如url为ab )时,它都表明我的站点具有ERR_TOO_MANY_REDIRECTS并且它在http://abhttps://ab之间重定向(或在http://ab/signinhttps://ab/signin )。 但是,当我访问管理仪表盘( https://ab/ghosthttp://ab/ghost )时,它按预期方式工作(无错误,正确重定向以使用HTTPS)。

有什么帮助吗?

我的Nginx配置:

# Configuration for http://a.b
server {
    listen 80;
    server_name a.b;
    location ^~ /ghost { # /ghost should be accessed securely
        return 301 https://$host$request_uri;
    }
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:2368;
    }
}

# Configuration for http://a.b
server {
    listen 443 ssl;
    server_name a.b;
    ssl_certificate ...;
    ssl_certificate_key ...;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers '...';

    location ^~ /ghost { # /ghost should be accessed securely
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:2368;
    }
    location / { # Force to use HTTP
        return 301 http://$host$request_uri;
    }
}

任何形式的帮助将不胜感激:')

https://github.com/TryGhost/Ghost/issues/2796

location ^~ /ghost { # /ghost should be accessed securely
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header HOST $host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:2368;
}

暂无
暂无

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

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