Nginx 背后的 Apache 由于 DirectorySlash 重定向而暴露自己

标签 apache nginx

我在端口 8097 上运行 Apache,并且 Nginx 代理对其的请求:

location / {
    proxy_pass         http://127.0.0.1:8097;

    proxy_redirect          off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size    10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout   90;
    proxy_send_timeout      90;
    proxy_read_timeout      90;
    proxy_buffers           32 4k;
}

Apache 配置(有意义的部分):

    <Directory /home/some/htdocs>
            Options FollowSymLinks
            Options -Indexes
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

那么会发生什么:当我访问 www.mysite.com/photos 并存在一个目录 photos 时,Apache 将我重定向到该目录并添加了斜杠。但由于某种原因,它实际上将我重定向到 www.mysite.com:8097/photos/ 我在浏览器中看到了这个地址,但我实际上不应该这样做:

HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.4
Date: Thu, 01 Nov 2012 10:28:13 GMT
Content-Type: text/html; charset=iso-8859-1
Connection: keep-alive
Location: http://www.mysite.com:8097/photos/

我知道我可以通过 UseCanonicalName On 解决这个问题(不是最好的解决方案 - 如果我没有规范名称怎么办?)但我仍然想知道,实际的 apache 端口是如何发生的通过这种重定向公开(但所有其他重写和重定向都可以正常工作)。

最佳答案

我找到了一种在 nginx 配置中修复它的方法。需要将端口添加到 Host header

proxy_set_header        Host            $host:$server_port;

关于Nginx 背后的 Apache 由于 DirectorySlash 重定向而暴露自己,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13174922/

相关文章:

django - 当大请求正文和过期 session 时,Nginx+uWSGI+Django 返回 502

node.js - AWS Elastic Beanstalk - NodeJS : Get certificate SSL from Letsencrypt without Beanstalk Load Balancer

java - 如何从Spring Security获取密码?

php - 将每个人从东部标准时间上午 8 点到午夜的网站访问权限更改为从午夜到上午 8 点只有我的 IP

linux - 在专用主机上安装 Apache 服务器

utf-8 - 使用 pcre 8.3 在 nginx 上使用 unicode url 重写规则失败

apache - 如何使用 Apache 反向代理动态端口?

php - 在 apache + php 和新的 nginx rails 上并排运行旧站点

http - 如何与 Golang 一起使用 nginx 作为反向代理?

jsp - 如何隐藏/更改浏览器地址栏上的 jsp 扩展名?