为什么是http://compassionpit.com/blog/经历了无限重定向循环?这是我的 nginx conf 文件。该网站由端口 8000 上的 nodejs 服务器运行,Apache 提供博客 (wordpress) 和论坛 (phpBB)。论坛解析正常,http://www.compassionpit.com/forum/...
server {
listen 80;
server_name www.compassionpit.org;
rewrite ^/(.*) http://www.compassionpit.com/$1 permanent;
}
server {
listen 80; # your server's public IP address
server_name www.compassionpit.com;
index index.php index.html;
location ~ ^/$ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location @blogphp {
internal;
root /opt/blog/;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8080;
}
location ~ ^/(forum|blog)/($|.*\.php) {
root /opt/;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8080;
}
location ~ ^/(forum|blog) {
root /opt/;
try_files $uri $uri/ @blogphp;
}
location ~ ^/(forum|blog)/ {
root /opt/;
}
location @backend {
internal;
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ / {
root /opt/chat/static/;
try_files $uri $uri/ @backend;
}
}
答案1
我认为您可能在配置 Wordpress 时没有在其 URL 中使用“www”子域,这与您配置 Nginx 的方式(使用server_name www.compassionpit.com
)相冲突。
因此,当您访问compassionpit.com/blog/Nginx 将您重定向到www.compassionpit.com/blog/,此请求随后到达 Wordpress,Wordpress 将您重定向回裸域compassionpit.com/blog/。
答案2
Nginx 可能继续处理其他 if 语句。在 if 语句末尾添加“break”
location ~ ^/(forum|blog)/($|.*\.php) {
root /opt/;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8080;
break;
}