› 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 · 3965 views
    This topic created in 2433 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
    leahoop
    Mar 5, 2020❤️1
    1
    location /api1/auth/loginout {
    proxy_pass http://ip/auth/loginout;
    }
    wsb200514
    wsb200514
    Mar 5, 2020❤️2
    2
    增加一个'/':
    location /api1/ {
    proxy_pass http://192.168.0.1:5000/;
    }
    或者:
    location /api1/auth/ {
    proxy_pass http://192.168.0.1:5000/auth/;
    }
    等等。
    写法有很多,最好查一下相关文档,全面理解一下。
    zhuangjia
    zhuangjia
    Mar 5, 2020
    3
    2 楼正解
    GM
    GM
    Mar 5, 2020❤️1
    4
    location /api1/ { <-------------注意结尾这个斜杠,必须要有
    proxy_pass http://192.168.0.1:5000/;
    }
    Shoukaku
    Shoukaku
    Mar 6, 2020❤️1
    5
    是只有 /api1/auth/loginout/这个请求吗,还是 /api1 下的所有请求?
    可以看一下 nginx 的 rewrite 模块,我觉得是跟你需求比较接近的一种简单的实现方式
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1369 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 22:11 · PVG 06:11 · LAX 14:11 · JFK 17:11
    ♥ Do have faith in what you're doing.