没有proxy_set_header主机,无法访问wordpress前端页面

时间:2017-03-29 06:24:58

标签: php wordpress apache nginx

我使用nginx作为apache wordpress站点的反向代理。但是如果我注释掉proxy_set_header部分,我就无法访问word.com前端页面,它只是重定向到我的浏览器中的127.0.0.1。谁能为我解释一下? Nginx设置:

server {
    listen 80 default_server;
    server_name word.com
    charset utf-8;
    index index.htm index.html;
    access_log /var/log/nginx/word-access.log main;
    error_log /var/log/nginx/word-error.log;

    location / {
        proxy_pass http://127.0.0.1:8080;
    }

    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
}

1 个答案:

答案 0 :(得分:0)

如果没有proxy_set_header指令,nginx会将代理的Host标头设置为127.0.0.0:8080

Apache会看到这个主机名,并在构建对浏览器的某些响应时使用它(例如重定向)。

通常指定proxy_set_header Host $host;。默认值仅在有限的情况下有用,例如联系远程资源。

有关详情,请参阅this document