11
如果您想通过基于位置的proxypass将代理URL请求代理到两个不同后端,最快和最干净的解决方案是什么。每个位置的Nginx /通过重写uri到proxy_pass
location /app1/ {
alias /var/www/ruby/public;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
try_files $uri $uri/ @ruby;
}
location @ruby {
proxy_pass http://127.0.0.1:3000;
}
location /app2/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
try_files $uri $uri/ @other;
}
location @other {
proxy_pass http://127.0.0.1:8080;
}
有了这个配置nginx的通行证“/ APP1”或“/ APP 2”,以代理和后端无法识别URL /命令..
如例如想传递给http://127.0.0.1:3000
只/messages
当访问http://<nginx>/app1/messages
- 但在配置上面也通过/app1/
为http://127.0.0.1:3000/app1/messages
。这同样适用于/app2
这并不是由于工作'“proxy_pass不能有URI部分位置由正则表达式给出......“',请参阅http://stackoverflow.com/questions/21662940/proxy-pass-cannot-have-uri-part-in-location。 – frhd