nginx使用proxy_pass指令配置请求uri替换

    配置nginx的location,在proxy_pass后配置upstream配置中,正常配置是上游服务地址和端口,则请求uri不变进行转发,若是配置带有uri,则按照配置的的uri进行替换后转发。nginx

正常配置:后端

       location = /uri/uri {
          proxy_pass http://upstream1;
       }tomcat

       upstream upstream1 {
        server 10.0.0.1:80 weight=10;
        }server

    客户端发送请求:http:nginx_ip:nginx_port/uri/uri, nginx的发送上游请求是:http:10.0.0.1:80/uri/uri。接口

配置增长uri:ip

       location = /uri/uri {
          proxy_pass http://upstream1/test/test;
       }部署

       upstream upstream1 {
        server 10.0.0.1:80 weight=10;
        }io

        客户端发送请求:http:nginx_ip:nginx_port/uri/uri, nginx的发送上游请求是:http:10.0.0.1:80/test/test。test

当前的需求是,对方向咱们推送数据,他们是固定的uri,要求咱们适配他们的接口,他们只配置咱们的ip和端口号。而咱们这边是应用是部署tomcat中,要是在应用层实现,则须要修改tomcat的server配置和修改服务中配置的接口uri,比较麻烦。经过上面的方式任意匹配uri,适配后端服务,更简单点。stream

相关文章
相关标签/搜索