[英]nginx proxy based on location
I would like to setup an nginx proxy that is based on a location instead of the listening port or server_name. 我想设置一个基于位置而不是监听端口或server_name的nginx代理。
upstream cluster
{
server cluster1:8080;
server cluster2:8080;
}
server
{
listen 80;
server_name mydomain.com;
location /hbase
{
proxy_pass http://cluster;
proxy_set_header X-Real-IP $remote_addr;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
}
}
I know this is probably something really simple that I am missing. 我知道这可能是我真正想不到的事情。 Basically the routing seems to work, but it actually ends up calling "http://cluster1:8080/hbase" when it should just route the traffic to the server without the hbase portion. 基本上,路由似乎可以正常工作,但实际上它实际上只是在将流量路由到没有hbase部分的服务器时最终调用了“ http:// cluster1:8080 / hbase”。
A rewrite rule would work, but I can't seem to find a way to rewrite in nginx; 重写规则会起作用,但是我似乎找不到在nginx中进行重写的方法。 I can get it to redirect, but I want the actual port to be invisible to the outside world. 我可以重定向它,但是我希望实际的端口对于外界是不可见的。
This works perfectly, but I only want to allow traffic on port 80. 这可以正常工作,但是我只想允许端口80上的流量通过。
upstream cluster
{
server cluster1:8080;
server cluster2:8080;
}
server
{
listen 555;
server_name mydomain.com;
location /
{
proxy_pass http://cluster;
proxy_set_header X-Real-IP $remote_addr;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
}
}
Is there possibly a way to use regex to remove hbase from the forwarded request? 是否有可能使用正则表达式从转发的请求中删除hbase?
ANSWER: 回答:
location /hbase
{
rewrite ^/hbase$|^/hbase/$|^/hbase/(.*)$ /$1 break;
proxy_pass http://cluster;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.