首页 > 解决方案 > 如何通过反向代理将 IP 作为远程主机名转发到 Apache?

问题描述

我使用 nginx 作为反向代理并将所有特定请求转发到 Apache 服务器。我的 nginx 配置如下所示:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name myserver.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

除了不是每个人都应该能够访问 Apache 服务器的某些位置之外,每件事都运行良好,所以我有一些特定位置的Require hostRequire ip。当我在没有 Nginx 反向代理的情况下直接为 Apache 提供服务时,我可以使用列入白名单的 IP 访问这些位置。但是启用反向代理后它不起作用。查看 Apache 日志(使用 记录vhost_combined)我总是得到localhost远程主机名。

我是否必须在 nginx 中设置另一个标头,还是必须在 Apache 中更改某些内容才能使用真实 ip 而不是 localhost?

标签: apachenginxreverse-proxy

解决方案


推荐阅读