nginx太多的redirect(cloudflare和https)

你好,谢谢你的帮助。

我search了,发现了类似的问题,但不是我所经历的。 当我尝试configurationnginx来服务我的应用程序时,我得到“太多redirect”。

这是:80服务器configuration

server{ listen 80; listen [::]:80; server_name app.domain.com; location /{ # This is an acceptable config: If request went trought http, # redirect to https server if ($scheme = "http"){ return 301 https://$host$request_uri; } # This is what i REALLY want: If request went trought http (this # server is listening port 80) and the user agent does not match, # then redirect to https, else show a specific html #if ($http_user_agent !~* "SPECIFIC USER AGENT" ) { # return 301 https://$host$request_uri; #} #if ($http_user_agent = "SPECIFIC USER AGENT" ) { # return 301 https://app.domain.com/specific.html; #} } location /specific.html { root /home/htmls/; autoindex off; } # This is required for the acme challenge oof Let's encrypt location /.well-known/acme-challenge { alias /etc/letsencrypt/webrootauth/.well-known/acme-challenge; } } 

这是https服务器:443

 server { listen 443 ssl; listen [::]:443 ssl; server_name app.domain.com; access_log /var/log/nginx/app-access.log; error_log /var/log/nginx/app-error.log; ssl on; ssl_certificate /etc/letsencrypt/live/app.domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/app.comain.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl_prefer_server_ciphers on; charset utf-8; location / { proxy_redirect off; proxy_http_version 1.1; proxy_read_timeout 90s; proxy_connect_timeout 90s; #proxy_set_header Host $http_host; 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 http://127.0.0.1:8000; } } 

我已经configuration我的networking服务器应用程序添加SSLauthentication。 该网站的后面是cloudflare保护(但禁用此特定的子域)。 我正在与我们encryptioncertbot。 我的应用程序工作得很好,我已经重新authentication了几次,但最后一个“太多redirect”问题出现了。

我已经尝试过几个cloudflare cryptconfiguration。 我可以回答几乎所有你可以问我的情况。 结果总是一个“太多的redirect”,或一个不可访问的网站。

请帮帮我! 这让我疯狂:S

不要让所有的服务器在域上进行重写,为什么不让Cloudflare用它的stream量规则来做到这一点。 简单重写http:// * – > https:// *

很明显,你可以自定义这个,然后添加到你想显示给用户的任何错误页面中,但是在这里实现这个更快,因此减less了原始服务器的stream量。