Reputation: 208
I would like to setup an nginx proxy that is based on a location instead of the listening port or server_name.
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.
A rewrite rule would work, but I can't seem to find a way to rewrite in 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.
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?
ANSWER:
location /hbase
{
rewrite ^/hbase$|^/hbase/$|^/hbase/(.*)$ /$1 break;
proxy_pass http://cluster;
}
Upvotes: 1
Views: 2471
Reputation: 28850
There is an efficient rewrite in nginx. The following should work (didn't try)
location /hbase
{
rewrite ^.*$ / break;
proxy_pass http://cluster;
Upvotes: 1