我知道这个问题已经被问及答复了一百万次,但是没有一个被接受的答案正在为我工作。 当我强制所有连接到https时,由于某种无限的redirect循环,我的网站无法访问。
root /usr/share/nginx/html/flawedspirit.com/root_html; index index.php index.html index.htm; error_page 403 /index.php; error_page 404 /error/404.php; error_page 500 502 503 504 /error/50X.php; access_log /usr/share/nginx/html/flawedspirit.com/logs/access.log; error_log /usr/share/nginx/html/flawedspirit.com/logs/error.log; server { listen 80 default_server; server_name flawedspirit.com; return 301 https://$server_name$request_uri; location ~ \.php { try_files $uri $uri/ =404; include fastcgi_params; fastcgi_pass php5-fpm-sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; } location ~ /\. { access_log off; log_not_found off; deny all; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|woff|ttf|svg)$ { expires max; log_not_found off; } } server { listen 443 ssl; server_name flawedspirit.com; ssl on; ssl_certificate <...>; ssl_certificate_key <...>; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM"; ssl_prefer_server_ciphers on; ssl_ecdh_curve secp521r1; location ~ \.php { try_files $uri $uri/ @no-extension; include fastcgi_params; fastcgi_pass php5-fpm-sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS on; fastcgi_intercept_errors on; } location @no-extension { rewrite ^(.*)$ $1.php last; } location ~ /\. { access_log off; log_not_found off; deny all; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|woff|ttf|svg)$ { expires max; log_not_found off; } }
那么我做错了什么?
好吧,也许这是一个caching问题,只是不在我预期的第一位。 我去了Cloudflare,在那里烧了我的网站caching,并将我的SSL设置设置为“完整”。 这似乎做到了。
编辑:我不能select这个作为48个多小时的答案,所以考虑这个答案。
我真的怀疑问题在这里:
location @no-extension { rewrite ^(.*)$ $1.php last; }
它不会产生你正在谈论的无限循环吗? 由于HTTPconfiguration似乎没问题,而且该位置仅存在于HTTPS版本中。 所以尝试直接连接到https。 如果我是正确的,你应该得到相同的循环。