1

I am trying to use nginx to direct a website hosted on port 8080 to domain exemple1.com and another one on port 8081 that i want to redirect to domain exemple2.com. On the file /etc/nginx/sites-available/default i puted this code:

location ~/example1/ {
    proxy_pass http://example1.com;
}
location ~/example2/ {
    proxy_pass http://example2.com;
}

but i couldn make it work . I am running 2 nodejs servers on the ports i talked about (port 8080 and 8081). What i am doing wrong and how to "fix " it?

1 Answer 1

1

Because the downstream app server running on different ports(listen) than coming in, you need to specify ports in proxy_pass. So I think

listen 8080; 

location ~/example1/ {
    proxy_pass http://example1.com:8080;
}
location ~/example2/ {
    proxy_pass http://example2.com:8081;
}
Sign up to request clarification or add additional context in comments.

2 Comments

but when i do sudo nginx -t i get this: nginx: [emerg] "listen" directive is not allowed here in /etc/nginx/sites-enabled/default:20 nginx: configuration file /etc/nginx/nginx.conf test faile
@FlorinBaciu you create a .conf file under /etc/nginx/conf.d and you can have server { listen ... } inside.

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.