如何通过Nginx反向代理特定的URL? [英] how to reverse proxy via nginx a specific url?

查看:974
本文介绍了如何通过Nginx反向代理特定的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在http://localhost:8080的服务器,我希望该服务器的特定url由nginx代理.

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

例如,我只希望将http://localhost:8080/test/(.*)反向代理为http://localhost/test/(.*).

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

我正在将另一台服务器部署到http://localhost/.

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

推荐答案

我以这种方式成功实现了这一目标.无论如何,谢谢您的评论. :)

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/;
    }
}

这篇关于如何通过Nginx反向代理特定的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆