如何在nginx中指向代理服务器的多个路径 [英] How to point many paths to proxy server in nginx

查看:219
本文介绍了如何在nginx中指向代理服务器的多个路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置将处理各种路径并将它们代理到我的 web 应用程序的 nginx 位置.

这是我的配置:

<预>服务器 {听80;server_name www.example.org;#这很好用地点/{proxy_set_header X-Forwarded-Host $host;proxy_set_header X-Forwarded-Server $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://localhost:8081/myApp/;}#不工作位置 ~ ^/(.+)$ {proxy_pass http://localhost:8081/myApp/$1;}}

我想通过各种路径访问 myApp,例如:/myApp/ABC、/myApp/DEF、myApp/GEH 或/myApp/ZZZ.当然,这些路径在 myApp 中是不可用的.我希望他们指向 myApp 的根目录并保留 url.可以用 nginx 存档吗?

解决方案

一个很晚的回复.这可能会帮助某人

试试proxy_pass/myApp//location1/location2;

每个位置用空格分隔.

I'm trying to set nginx location that will handle various paths and proxy them to my webapp.

Here is my conf:

    server {

    listen          80;
    server_name     www.example.org;

    #this works fine
    location / { 
       proxy_set_header X-Forwarded-Host $host;
       proxy_set_header X-Forwarded-Server $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_pass http://localhost:8081/myApp/;
    }

    #not working
    location ~ ^/(.+)$ { 
       proxy_pass http://localhost:8081/myApp/$1;
    }
}

I would like to access myApp with various paths like: /myApp/ABC, /myApp/DEF, myApp/GEH or /myApp/ZZZ. Of course these paths are not available in myApp. I want them to point to root of myApp and keep url. Is that possible to archive with nginx ?

解决方案

A very late reply. this might help someone

try proxy_pass /myApp/ /location1 /location2;

Each location separated with space.

这篇关于如何在nginx中指向代理服务器的多个路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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