为什么http://compassionpit.com/blog/会经历无限的redirect循环? 这是我的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; } }
我想你可能已经configuration了没有'WWW'子域的WordPress的URL,这与你configurationNginx的方式(使用server_name www.compassionpit.com )是冲突的。
所以,当你访问compassionpit.com/blog/时, Nginx会将你redirect到www.compassionpit.com/blog/ ,然后这个请求就会到达Wordpress,将你redirect到裸露的域名compassionpit.com/blog/ 。
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; }