redirect - Nginx反向代理导致无限循环

标签 redirect nginx virtualhost reverse-proxy redirect-loop

我的 Nginx 站点配置文件中有以下内容:

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。

如果有人能告诉我我做错了什么,我将非常感激。非常感谢!

最佳答案

我遇到了同样的问题,按照 Alexey Ten 的建议,解决方案是删除 Host header 。

关于redirect - Nginx反向代理导致无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32362396/

相关文章:

javascript - 规避asp事件处理程序

apache - 如何根据查询字符串重定向URL?

docker 命令未运行

Apache2.4 _default_ 的优先级 :443 over first *:443 virtualhost definition

linux - 从 virtualhost proxypass 中排除别名

bash - Bash脚本,错误输出重定向

python - Django+Gunicorn+nginx Internal Server Error,错误在哪里,如何解决?

html - 发送图片数据时413 Request Entity Too Large

macos - OSX Mountain Lion 网络服务器上的 ServerAlias 无法解析

c++ - 是否可以使用重定向到标准输入通过命名管道读取间歇性发送的数据?