3

I have an nginx instance running on port 80 and another app (embedded jetty) running on the same machine on port 4567.

I'm trying to redirect any request that includes /api/ in the URL, to the server running on port 4567.

For this, I've added the following inside the http context tag in the nginx.conf file:

server {
        listen 80;
        location /api {
                proxy_pass http://127.0.0.1:4567;
        }
}

But this is not working. I simply get a 404 Not Found from nginx whenever I try to request any URL that includes /api/*.

What am I missing? Thanks.

Henrique
  • 153
  • 1
  • 5

2 Answers2

1

I think you location is incorrect, use

location /api/ { 
 proxy_pass http://127.0.0.1:4567; 
}

Add slash in the end of your location.

0

Found the solution.

Instead of adding this configuration to nginx.conf, I added it to /etc/nginx/sites-enabled/default and it seems to have done the trick.

Henrique
  • 153
  • 1
  • 5
  • The best practice is to create a new file in `sites-available`, and make a symbolic link to `sites-enabled`. This way every virtualhost has its own configuration file. In your case, you could remove `sites-enabled/default`, to remove the current default vhost, and make a new one with another file. – Tero Kilkanen Jul 11 '15 at 01:37