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.

Here is the problem: I have two domains which have pointed to two available IPs on a server. Say:

siteone.com pointed to 1.2.3.4 sitetwo.com pointed to 1.2.3.5

What I did to configure nginx vhosts was to put

server {
        listen    site1.com:80; # 
        server_name   site1.com www.site1.com;

on vhost1 file and

server {
        listen    site2.com:80; # 
        server_name   site2.com www.site2.com;

on a (separate) vhost2 file. The two vhost files are exact replicates expect the site1 and site2 paths, of course. And vhost1 is working well on its own.

However after restarting nginx I get this error:

Restarting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok [emerg]: bind() to 1.2.3.5:80 failed (99: Cannot assign requested address) configuration file /etc/nginx/nginx.conf test failed

When I put

server {
        listen   *:80; # 
        server_name   site2.com www.site2.com;

On site2 vhost, the nginx restarts without error but does not render pages on site2 path.

I'm confused and appreciate your help.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Try this:

server {
    listen    1.2.3.4:80; # 
    server_name   site1.com www.site1.com;
    ...
}

server {
    listen    1.2.3.5:80; # 
    server_name   site2.com www.site2.com;
    ...
}
share|improve this answer
    
You beat me to it! –  Joel E Salas Sep 10 '12 at 19:08
    
Do you mean putting both directives on vhost1 file? –  alfish Sep 10 '12 at 19:09
    
@alfish: no matter. You can put it in anywhere you want (as long as it is included in the main configuration file). –  quanta Sep 10 '12 at 19:17
    
After doing this, I get the same error:"Restarting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok [emerg]: bind() to 1.2.3.5:80 failed (99: Cannot assign requested address)configuration file /etc/nginx/nginx.conf test failed" . How can I check that 1.2.3.5 is really usable, as my ISP claims? –  alfish Sep 10 '12 at 20:01
    
sudo /sbin/ip addr sh? –  quanta Sep 10 '12 at 20:04
show 3 more comments

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.