NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
334862132
V2EX  ›  NGINX

小白请教一个 nginx 的配置问题

  •  
  •   334862132 · Mar 5, 2020 · 3505 views
    This topic created in 2284 days ago, the information mentioned may be changed or developed.
    一个请求 /api1/auth/loginout/
    我在接收到 /api1/auth/loginout 的请求后要把请求首地址 api1 转发到另一个服务器的 auth/logunout/接口要如何去写
    这么写的话转发过去 请求接口依然是 /api1/auth/loginout
    location /api1 {
    proxy_pass http://192.168.0.1:5000/;
    }
    5 replies    2020-03-06 03:45:52 +08:00
    leahoop
        1
    leahoop  
       Mar 5, 2020   ❤️ 1
    location /api1/auth/loginout {
    proxy_pass http://ip/auth/loginout;
    }
    wsb200514
        2
    wsb200514  
       Mar 5, 2020   ❤️ 2
    增加一个'/':
    location /api1/ {
    proxy_pass http://192.168.0.1:5000/;
    }
    或者:
    location /api1/auth/ {
    proxy_pass http://192.168.0.1:5000/auth/;
    }
    等等。
    写法有很多,最好查一下相关文档,全面理解一下。
    zhuangjia
        3
    zhuangjia  
       Mar 5, 2020
    2 楼正解
    GM
        4
    GM  
       Mar 5, 2020   ❤️ 1
    location /api1/ { <-------------注意结尾这个斜杠,必须要有
    proxy_pass http://192.168.0.1:5000/;
    }
    Shoukaku
        5
    Shoukaku  
       Mar 6, 2020   ❤️ 1
    是只有 /api1/auth/loginout/这个请求吗,还是 /api1 下的所有请求?
    可以看一下 nginx 的 rewrite 模块,我觉得是跟你需求比较接近的一种简单的实现方式
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   889 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 22:34 · PVG 06:34 · LAX 15:34 · JFK 18:34
    ♥ Do have faith in what you're doing.