0

I'm trying to set up nginx to let the name node of a Hadoop based cluster that I set up effectively redirect to the different user interfaces surrounding Hadoop based off of the file extension on the url. For simplicity, say that

firstnode.com corresponds to the main node of my cluster
stormnode.com corresponds to the node running storm, and the UI is accessible at port 8080.

Then, the ideal redirection would be http://firstnode.com/storm ->http://stormnode.com:8080.

I have tried editing my Nginx configuration file such that I end up with something like each of the following:

server{
    listen 80;
    server_name firstnode.com;

    location /storm{
        proxy_pass secondnode.com:8080;
    }
}

as well as

server{
    listen 80;
    server_name firstnode.com;

    location /storm{
        return 301 $scheme://secondnode.com:8080$request_uri;
    }
}

as well as equivalent statements to the latter using regular expressions. Unfortunately, the closest that I have gotten is redirecting firstnode.com/storm to secondnode.com:8080/storm. I would greatly appreciate any advice on how to rewrite the URL through nginx's config files without passing the file extension/path (aka /storm) to the new URL.

  • Do you want nginx to proxy the request (user does not see the secondnode.com:8080 URL, or do you want to redirect user to the secondnode.com:8080 URL (user sees the URL in browser)? – Tero Kilkanen Jul 26 '16 at 20:52
  • I would prefer to redirect the user to the secondnode.com:8080 URL in the browser if possible, but it doesn't really matter that much in this application. I'm really just setting this up to avoid having to look up all of the ports to go the UIs, as my platform uses several of them. – Flowing Brooks Jul 26 '16 at 21:01
1

Try this:

server {
    listen 80;
    server_name firstnode.com;

    location ~ ^/storm(?<section>.*)$ {
        return 301 $scheme://secondnode.com:8080$section;
    }
}

Here we capture the part after /storm into section variable, and then use that variable in the return statement to form the desired path.

|improve this answer|||||
  • Thank you very much. I was having a bit of trouble figuring out the right regex to use, and this worked perfectly! – Flowing Brooks Jul 26 '16 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.