Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx: multiple locations on same server

Tags:

nginx

This is my nginx conf file.

server {
    listen 80;

    server_name example.com;

    location / {
        proxy_pass http://localhost:9000;
    }

    location /some/directory {
        proxy_pass http://localhost:8998;
    }
}

server {
    listen 80;

    server_name example2.com;

    location / {
        proxy_pass http://localhost:8999;
    }
}

For some reason example.com and example2.com are working, but example.com/some/directory is not.

  • localhost:9000 & localhost:8999: are harp.js sites, they have they own routing, and work properly, both locally and on the proxy-ed domains (example.com & example2.com).
  • localhost:8998: is a golang api, it works locally and also if I access example.com:8998 or example2.com:8998.

Is there something wrong with the conf?

EDIT: added more info to the question.

like image 408
Christian Gill Avatar asked Oct 20 '25 15:10

Christian Gill


1 Answers

server {
    listen 80;

    server_name example.com;

    location / {
        proxy_pass http://localhost:9000/;
    }

    location /some/directory {
        proxy_pass http://localhost:8998/;
    }
}

server {
    listen 80;

    server_name example2.com;

    location / {
        proxy_pass http://localhost:8999/;
    }
}

Try this, adding the last / in the proxy_pass's should work.

like image 196
Martin Bratteng Avatar answered Oct 23 '25 05:10

Martin Bratteng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!