我知道这个问题已经被问过和回答过一百万次了,但是所有被接受的答案都对我不起作用。当我将所有连接强制为 https 时,由于某种无限重定向循环,我的网站无法访问。
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;
}
}
那么我做错了什么?
答案1
好吧,也许这确实是个缓存问题,只是不是我预想的那样。我去了 Cloudflare,删除了我网站的缓存,并将 SSL 设置设为“完整”。这似乎解决了问题。
编辑:我不能在接下来的 48 小时内选择这个作为答案,所以请将其视为答案。
答案2
我确实怀疑问题就在这里:
location @no-extension {
rewrite ^(.*)$ $1.php last;
}
它不会产生您所说的无限循环吗?因为 HTTP 配置似乎没问题,并且该位置仅存在于 HTTPS 版本中。因此尝试直接连接到 https。如果我没记错的话,您应该会得到相同的循环。