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 · Apr 26, 2015 · 6939 views
    This topic created in 4052 days ago, the information mentioned may be changed or developed.
    例如这个配置:
    server {
    listen 127.0.0.1:80;
    server_name nginx;

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

    求解!啊!
    6 replies    2015-04-26 18:53:18 +08:00
    ryd994
        1
    ryd994  
       Apr 26, 2015
    你行尾没有;
    是复制错了么?
    末尾带/的话应该是可以的
    另外谷歌404里应该有相应的提示信息,到底是请求的是什么页面
    extreme
        2
    extreme  
       Apr 26, 2015
    Try to remove the "/" at the end of www.google.com.
    extreme
        3
    extreme  
       Apr 26, 2015   ❤️ 1
    @extreme 不对呢,末尾加了"/"才不传递location的URI……
    所以这个404错误应该不是/google/导致的。
    Misaka030
        4
    Misaka030  
       Apr 26, 2015   ❤️ 1
    应该要加个rewrite
    location /google/ {
    rewrite ^\/google(.*)$ $1 break;
    proxy_pass https://www.google.com/;
    }
    NiverR
        5
    NiverR  
    OP
       Apr 26, 2015
    @extreme 嗯谢谢,刚刚看了看配置文件的确没有uri,翻了翻官方的文档,没有Uri的话会默认将Location传递过去。
    usernametoolong
        6
    usernametoolong  
       Apr 26, 2015
    可以用proxy_redirect解决。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2861 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 07:23 · PVG 15:23 · LAX 00:23 · JFK 03:23
    ♥ Do have faith in what you're doing.