如何在nginx中指向代理服务器的许多路径
我试图设置nginx位置来处理各种路径,并将它们代理到我的webapp。
这是我的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;
}
}
我想通过诸如/ myApp / ABC,/ myApp / DEF,myApp / GEH或/ myApp / ZZZ等各种路径访问myApp。 当然,这些路径在myApp中不可用。 我希望他们指向myApp的根目录并保留url。 有可能使用nginx进行存档吗?
Nginx地址按照定义顺序匹配。 location /基本上是一个通配符位置,所以它会匹配所有内容,没有任何内容会到达第二个位置。 颠倒两个定义的顺序,它应该起作用。 但实际上,现在我更仔细地看待它,我认为这两个地点基本上都在做同样的事情:
/whatever/path/ ->>proxies-to->> http://localhost:8081/myApp/whatever/path/
非常迟的回复。 这可能有助于某人
try proxy_pass /myApp/ /location1 /location2;
每个位置都用空格隔开。
链接地址: http://www.djcxy.com/p/32541.html