NginX location 目录反向代理问题

2015-04-26 00:10:17 +08:00
 NiverR
例如这个配置:
server {
listen 127.0.0.1:80;
server_name nginx;

location /google/ {
proxy_pass https://www.google.com/
}
}
然后Google就会返回404错误(估计是把自己域名的/google/一起发送过去了)

求解!啊!
5790 次点击
所在节点    NGINX
6 条回复
ryd994
2015-04-26 01:10:15 +08:00
你行尾没有;
是复制错了么?
末尾带/的话应该是可以的
另外谷歌404里应该有相应的提示信息,到底是请求的是什么页面
extreme
2015-04-26 02:03:12 +08:00
Try to remove the "/" at the end of www.google.com.
extreme
2015-04-26 02:08:30 +08:00
@extreme 不对呢,末尾加了"/"才不传递location的URI……
所以这个404错误应该不是/google/导致的。
Misaka030
2015-04-26 05:47:08 +08:00
应该要加个rewrite
location /google/ {
rewrite ^\/google(.*)$ $1 break;
proxy_pass https://www.google.com/;
}
NiverR
2015-04-26 11:51:34 +08:00
@extreme 嗯谢谢,刚刚看了看配置文件的确没有uri,翻了翻官方的文档,没有Uri的话会默认将Location传递过去。
usernametoolong
2015-04-26 18:53:18 +08:00
可以用proxy_redirect解决。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/186354

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX