我有一个Nginx在80端口上运行的服务器作为代理Apache 2.2正在侦听127.0.0.1:8080
当我访问http://hostname/subfolder/它时效果很好。
当我访问http://hostname/subfolder它时,它会将我重定向到http://hostname:8080/subfolder/哪个错误。
据我看到了错误的重定向被Apache返回,但UseCanonicalName并UseCanonicalPhysicalProxy都设置为Off
关于如何解决这个问题的任何想法?
我也遇到了这个问题,我能够在我的 nginx 配置中的 proxy_pass 指令之后立即使用 proxy_redirect 指令修复它:
proxy_redirect http://example.com:8080/ http://example.com/
Run Code Online (Sandbox Code Playgroud)
这是我的完整 nginx 配置(在我的情况下,Apache 在端口 81 上并托管两个站点。我添加了两个特定于站点的 proxy_redirect 行,因为我不确定如何添加一个通用的行。)
server {
listen 80;
access_log /var/log/nginx/apache-proxy.access.log;
location / {
proxy_pass http://localhost:81;
#fix for apache redirects that include the port number
proxy_redirect http://nfriedly.com:81/ http://nfriedly.com/;
proxy_redirect http://misticflame.com:81/ http://misticflame.com/;
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 6000;
proxy_send_timeout 6000;
proxy_read_timeout 6000;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
send_timeout 6000;
proxy_buffering off;
proxy_next_upstream error;
}
}
Run Code Online (Sandbox Code Playgroud)
注意:这是 5 年前 nginx 的 pre-1.0 版本。这是当前版本的 proxy_redirect 文档:http ://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
也许 nginx 没有设置代理标头来告诉 apache 原始请求是什么样的。
在 Nginx 中:
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Run Code Online (Sandbox Code Playgroud)
请参阅http://wiki.nginx.org/LikeApache
| 归档时间: |
|
| 查看次数: |
7824 次 |
| 最近记录: |