how to reverse proxy via nginx a specific url?

假装没事ソ 提交于 2019-12-20 02:15:49

问题


I have a server running at http://localhost:8080 i want a specific url of this server to be proxied by nginx.

For example, i only want http://localhost:8080/test/(.*) to be reverse proxied to http://localhost/test/(.*).

I'm proxing another server to http://localhost/.


回答1:


What about just a simple location block?

server {
    # ... other stuff

    location /test/ {
        try_files $uri @testproxy;
    }

    location @testproxy {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        # all your params
    }
}



回答2:


I made it somehow this way and it worked. Thanks for your comment anyway. :)

server {
    listen 80;
    # ... other stuff

    upstream backend1 {
        server 127.0.0.1:8080;
    }

    location /test/ {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://backend1/test/;
    }
}


来源:https://stackoverflow.com/questions/23262663/how-to-reverse-proxy-via-nginx-a-specific-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!