Nginx反向代理导致无限循环 [英] Nginx reverse proxy causing infinite loop
问题描述
我的Nginx站点配置文件中包含以下内容:
I have the following in my Nginx site config file:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://localhost/page-1/;
}
}
仅当我添加proxy_set_header Host $host;
行时,才会出现此问题.看来$host
变量创建了一个重定向循环,并且错误服务器日志中的GET请求类似于此...page-1/page-1/page-1/page-1...
,服务器响应内部错误500.
The issue only seems to occur when I add the proxy_set_header Host $host;
line. It appears that the $host
variable creates a redirect loop and the GET request from the error server logs goes something like this ...page-1/page-1/page-1/page-1...
with the server responding with an internal error 500.
如果有人能告诉我我做错了什么,我将不胜感激.提前非常感谢!
I'd be really grateful if anyone could tell me what I'm doing wrong. Many thanks in advance!
推荐答案
我遇到了同样的问题,正如Alexey Ten所建议的那样,解决方案是删除Host标头.
I had the same issue, and as suggested by Alexey Ten, the solution is to remove the Host header.
这篇关于Nginx反向代理导致无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!