1

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;
}

1 Answer 1

1

There is an efficient rewrite in nginx. The following should work (didn't try)

  location /hbase
  {
     rewrite  ^.*$  /  break;
     proxy_pass http://cluster;
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I had tried that, but wasn't thinking to add all three cases into the regex.
Oh ok, didn't know there was something after /hbase/. Glad it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.