redirect循环SSL Nginx Cloudflare

我有CloudFlare的通用SSL。 我想在我的Ghost博客上build立一个永久SSLredirect

这是我的原始configuration。 它可以单独使用http://example.com和https://example.com

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name example.com; # Replace with your domain root /usr/share/nginx/html; index index.html index.htm; client_max_body_size 10G; location / { proxy_pass http://localhost:2368; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; } } 

这是我尝试configuration为从HTTPredirect到HTTPS,但它导致redirect循环

 server { listen 80 default_server; server_name example.com; return 301 https://example.com$request_uri; } server { listen 443 ssl; ssl on; ssl_certificate /etc/nginx/ssl/cert/example.crt; ssl_certificate_key /etc/nginx/ssl/private/example.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; server_name example.com; # Replace with your domain root /usr/share/nginx/html; index index.html index.htm; client_max_body_size 10G; location / { proxy_pass http://localhost:2368; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; } } 

不完全确定为什么它的循环。

我没有足够的代表来添加上面的评论,但我也遇到了这个问题,我设法解决这个问题的唯一方法是禁用CloudFlare的特定的DNS条目,这显然是不理想的。

基于此,似乎CloudFlare正在为已经具有SSL(启用了从HTTP到HTTPS的redirect)的DNS条目实现通用SSL的方式存在问题。 此外,似乎您可以禁用特定的DNS条目的CloudFlare SSL。

对不起,我不能更有帮助,但如果我find一个解决scheme,我一定会在这里发布。

受Pascal的回答启发,我尝试修改cloudflare和我的服务器之间的连接types,从灵活的ssl完整的ssl 。 对我来说,这是有效的。

事后看来这似乎是合乎逻辑的,因为灵活的sslstream程是:

  1. 用户通过ssl连接到cloudflare
  2. cloudflare通过普通的http连接到服务器
  3. 服务器发出redirect作为响应
  4. cloudflare将响应转发给客户端(redirect)
  5. 冲洗并重复

如果我启用完整的ssl ,redirect不会再发生,因为cloudflare通过ssl连接到服务器。

我有同样的问题,并最终在Ghost的config.js设置urlurlSSL 。 这不会强制SSL,但是如果用户通过https访问博客,设置这将确保所有未来的导航也将通过https完成。

之前,如果用户点击博客post,然后点击任何其他内部链接,该链接将通过http服务,以及所有其他未来的请求。 设置urlSSL属性至less修复了这个问题。

 url: http://blog.example.com, urlSSL: https://blog.example.com 

参考: http : //support.ghost.org/config/#ssl

我刚刚在我的鬼实例中遇到了同样的问题,并在这里讨论了一下:

https://stackoverflow.com/questions/40816988/infinite-redirect-nginx/40817660#40817660

事实certificate,我有两个问题无限的redirect问题[(┛◉Д◉)┛彡┻┻┻┻],一个用我的服务器configuration,一个用我的cloud-flareconfiguration。

要在云端使用SSL,您需要:

  • 转至概览选项卡>设置摘要>单击SSL并将SSL从“灵活”更改为“完整(严格)”。
    • 这也可以在encryption选项卡> SSL>点击SSL并将SSL从“灵活”更改为“完整(严格)”中find。

既然你在vHost中引用了端口2368的代理传递,那么你可能也会运行ghost,这似乎是合乎逻辑的。 (我意识到这不是在该端口上运行的唯一软件。)

  • 检查你的config.js以确保url:被指向http不是 https