V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
NiverR
V2EX  ›  NGINX

NginX location 目录反向代理问题

  •  
  •   NiverR ·
    xTHAT · 2015-04-26 00:10:17 +08:00 · 5778 次点击
    这是一个创建于 3278 天前的主题,其中的信息可能已经有所发展或是发生改变。
    例如这个配置:
    server {
    listen 127.0.0.1:80;
    server_name nginx;

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

    求解!啊!
    6 条回复    2015-04-26 18:53:18 +08:00
    ryd994
        1
    ryd994  
       2015-04-26 01:10:15 +08:00
    你行尾没有;
    是复制错了么?
    末尾带/的话应该是可以的
    另外谷歌404里应该有相应的提示信息,到底是请求的是什么页面
    extreme
        2
    extreme  
       2015-04-26 02:03:12 +08:00
    Try to remove the "/" at the end of www.google.com.
    extreme
        3
    extreme  
       2015-04-26 02:08:30 +08:00   ❤️ 1
    @extreme 不对呢,末尾加了"/"才不传递location的URI……
    所以这个404错误应该不是/google/导致的。
    Misaka030
        4
    Misaka030  
       2015-04-26 05:47:08 +08:00   ❤️ 1
    应该要加个rewrite
    location /google/ {
    rewrite ^\/google(.*)$ $1 break;
    proxy_pass https://www.google.com/;
    }
    NiverR
        5
    NiverR  
    OP
       2015-04-26 11:51:34 +08:00
    @extreme 嗯谢谢,刚刚看了看配置文件的确没有uri,翻了翻官方的文档,没有Uri的话会默认将Location传递过去。
    usernametoolong
        6
    usernametoolong  
       2015-04-26 18:53:18 +08:00
    可以用proxy_redirect解决。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5261 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:40 · PVG 13:40 · LAX 22:40 · JFK 01:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.