11

I would like to have several Nginx instances running on my server on separate ports (for example one user runs Nginx on port 2345, and another user on port 2346). So far, I have been successful in compiling and running the server on their designated ports. However, I am running into a weird issue: If i visit domain1.com:2345 or domain2.com:2346 I get the correct (200) response but if I visit domain1.com or domain2.com (without specifying the port) I get no response at all.

Any help/clues in figuring out how to set this up would be highly appreciated.

1
  • Does it need to be different users? Can't you just use virtual hosts to do that and use the Listen directive to make nginx listen in different ports? Explain what exactly what you are trying to achieve.
    – coredump
    Mar 3, 2011 at 13:08

3 Answers 3

14

Okay, I found a solution.

What I did was run a 'master' server, as root, on port 80. From there I add server blocks for each server on their ports with a proxy_pass directive to the server.

  server {
    listen      80;
    charset     utf-8;
    server_name domain1.com;
    location / {
        proxy_pass http://domain1.com:2345;
  }
  server {
    listen      80;
    charset     utf-8;
    server_name domain2.com;
    location / {
        proxy_pass http://domain2.com:2346;
  }

Perhaps there is a more elegant solution but this seems to work well.

1
  • What was there in your "master" server ?
    – Faiz Ahmed
    Feb 16 at 17:26
4

Webbrowsers automatically choose port 80 if you don't specify a port. From your explanation it seems like none of the two instances listen on port 80.

What you might want to do is instead serve both domain1.com and domain2.com from the same nginx instance using virtual hosts.

1
  • Thanks for the tip. The port 80 info was a good start... However, I wanted to give users the ability to configure their own Nginx instances on their accounts and not just virtual hosts.
    – Edvinas
    Mar 3, 2011 at 14:21
1

If it is possible for you to have multiple ip addresses for your server you can run several nginx instances on port 80 given that you specify different ip-addresses in the listen directive.

An example:

On the first instance:

server {
  listen a.b.c.e:80
  ...
}

On the other instance

server {
  listen f.g.h.i:80
  ...
}

However this will become a pain if you have more than just a couple of users. Also multiple public ip-addresses might be hard to come by.

You must log in to answer this question.

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