问题描述
我正在尝试设置NGINX和cloudflare. 我已经在Google上阅读了有关此内容的信息,但没有任何解决方案能解决我的问题.目前,我的cloudflare处于活跃状态.我删除了cloudflare中的所有页面规则,但之前没有domain.com和www.domain.com使用HTTPS.我以为这可能是导致问题的原因,所以我将其删除.这是我的default
NGINX文件,目的是仅允许通过域名访问而禁止通过网站的IP值访问:
I'm trying to set up NGINX and cloudflare. I've read about this on Google but nothing solved my problem. My cloudflare is active at the moment. I removed all page rules in cloudflare but before had domain.com and www.domain.com to use HTTPS. I thought this could be causing the problem so I removed it. Here is my default
NGINX file, with purpose of allowing only access by domain name and forbid access by IP value of the website:
server{
#REDIRECT HTTP TO HTTPS
listen 80 default;
listen [::]:80 default ipv6only=on; ## listen for ipv6
rewrite ^ https://$host$request_uri? permanent;
}
server{
#REDIRECT IP HTTPS TO DOMAIN HTTPS
listen 443;
server_name numeric_ip;
rewrite ^ https://www.domain.com;
}
server{
#REDIRECT IP HTTP TO DOMAIN HTTPS
listen 80;
server_name numeric_ip;
rewrite ^ https://www.domain.com;
}
server {
listen 443 ssl;
server_name www.domain.com domain.com;
#rewrite ^ https://$host$request_uri? permanent;
keepalive_timeout 70;
ssl_certificate /ssl/is/working.crt;
ssl_certificate_key /ssl/is/working.key;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
#ssl_dhparam /path/to/dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM$
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;
(...) more ssl configs
可能会发生什么?如有需要,我会提供mroe信息...
What could be off? I'll provide mroe information if needed...
推荐答案
在试用后发现这仅与Cloudflare有关.因为在转到Coudflare之前我没有重定向问题.
After tryouts found that this is only related with Cloudflare. Because I had no redirect problem before moving to Coudflare.
在我看来,这是一个简单的解决方法.选择[加密]框,然后选择完全(严格),如图中所示.
In my case was simple fix like this. Select [Crypto] box and select Full (strict) as in the image.
真的,您可以先尝试此操作,然后再执行其他操作.
Really, you can try this out first before any other actions.
这篇关于Cloudflare和Nginx:重定向过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!