nginx实现动态代理

2023-10-15  本文已影响0人  雨中星辰0
作者 时间
雨中星辰 2023-10-16

需求说明

需要用nginx代理一个应用的请求,但是该没有一个统一的url前缀。
就需要把:http://nginx ip/service-gateway/的请求转发到http://10.35.13.191:9095/
例如:
http://nginx ip/service-gateway/index.html转发后为http://10.35.13.191:9095/index.html
http://nginx ip/service-gateway/api/list转发后为http://10.35.13.191:9095/api/list

nginx配置

    location /service-gateway {
            proxy_pass http://10.35.13.191:9095/;
    }

上面的nginx配置中的location /service-gateway指定了一个URL路径前缀为/service-gateway的位置块。当nginx收到请求时,如果请求的URL以/service-gateway开头,就会将该请求转发到http://10.35.13.191:9095/

具体解释如下:

这样配置后,当请求http://nginx ip/service-gateway/hello时,nginx会将该请求转发到http://10.35.13.191:9095/hello,并且在转发时不再附加/service-gateway前缀。

上一篇 下一篇

猜你喜欢

热点阅读