Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

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
    }
  }
}
share|improve this answer
add comment

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;
  }
}
share|improve this answer
    
No, I have my own servers listening in 3000 and 4000. –  barroco Jan 20 '12 at 14:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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