I have two HTTP servers. One of them (A) is listening to port 3000 and the other one (B) is listening to port 4000. Also, I have two domains example1.com and example2.com. In the other hand, I have nginx server listening at port 80.

I would like to get responses from server A when the request is using example1.com domain and responses from server B when the request is using example2.com.

How should I configure nginx?

link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

You have to use proxy_pass (which may require more configuration that this)

http://wiki.nginx.org/HttpProxyModule#proxy_pass

http {
  server {
    server_name www.example1.com;

    root /var/www/example1.com/htdocs;

    location / {
      proxy_pass http://127.0.0.1:3000/;
      // more configuration
    }
  }

  server {
    server_name www.example2.com;

    root /var/www/example2.com/htdocs;

    location / {
      proxy_pass http://127.0.0.1:4000/;
      // more configuration
    }
  }
}
link|improve this answer
feedback

You can setup vhost & alias for example1.com & exmaple2.com

cd /etc/nginx/sites-available/

create an virtual host for your domain for more detail follow this link. http://wiki.nginx.org/VirtualHostExample

http {
  index index.html;

  server {
    server_name www.example1.com;
    access_log logs/example2.access.log main;

    root /var/www/example.com/htdocs;
  }

  server {
    server_name www.exampl2.com;
    access_log  logs/example2.access.log main;

    root /var/www/example2.com/htdocs;
  }
}
link|improve this answer
No, I have my own servers listening in 3000 and 4000. – isola009 Jan 20 at 14:47
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.