0

I'm trying to build a website which links to multiple nodejs apps.

www.example.com/app1
www.example.com/app2

Both app1 and app2 are hosted on AWS Elastic Beanstalk.

http://app1.us-west-2.elasticbeanstalk.com
http://app2.us-west-2.elasticbeanstalk.com

How can I redirect sub-directories on example.com to these apps without changing the URL in the browser?

Should I create a 3rd app on EBS and associate example.com with it. Then use nginx on it to redirect to specific apps?

Sorry for the vagueness. I'm new to this stuff.

2 Answers 2

0

You could do it by nginx. Your config should look like this one:

server {
    listen       80;

    location /app1 {
        proxy_pass http://app1.us-west-2.elasticbeanstalk.com:80;
    }

    location /app2 {
        proxy_pass http://app2.us-west-2.elasticbeanstalk.com:80;
    }
}
1
  • I tried location ^~ /app1/ { rewrite ^/app1/(.*) http://app1.us-west-2.elasticbeanstalk.com/$1 permanent; } This redirects me to http://app1.us-west-2.elasticbeanstalk.com and changes the url in the browser, which I'm trying to avoid. Though, I'm not certain if your solution prevents that. I'll check. Jun 5, 2017 at 22:13
0

@Alexander Thanks. Though I had issues with static file getting 404 This did the trick: https://stackoverflow.com/questions/36849456/nginx-reverse-proxy-404-on-static-files

if ($uri ~ app1/) {
  break;
}

if ($http_referer ~ app1/ ) {
  rewrite (.*) /app1/$1 redirect;
}

location /app1/ {
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://app1.compute.amazonaws.com:3001/ ;
}

Though as noted in the link. It won't work for POST queries :/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .