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

I have a subdomain that I want to proxy through Nginx to Node.js.

domain.tld is currently routed the standard way through /opt/nginx/conf/nginx.conf.

However, I also want subdomain.domain.tld to route to domain.tld:8000.

To do this, I put the following in /etc/nginx/sites-available/subdomain.domain.tld.conf:

http{
    server {
            listen 0.0.0.0:80;
            server_name subdomain.tld.com;
            access_log /var/log/nginx/subdomain.domain.log;

            location / {
                    proxy_pass http://127.0.0.1:8000;
            }
    }
}

Nginx seems to start up fine. The subdomain's nameservers are configured correctly.

What am I doing wrong? Thanks a ton for any help in advance.

Edit: Also, I symlinked the file from sites-available/ to sites-enabled/.

Edit: The exact contents of /opt/nginx/conf/nginx.conf:

http://pastebin.com/wZJFPx7H

Edit: The error message starting nginx:

 Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
 nginx: [emerg] still could not bind()
share|improve this question
    
cross post of stackoverflow.com/questions/8903209/… –  Dan D. Jan 18 '12 at 1:25

1 Answer 1

up vote 1 down vote accepted

First off, check for any errors in the log during startup.

It may not be loading this server because of this:

proxy_pass 127.0.0.1:8000;

Which should be changed to:

proxy_pass http://127.0.0.1:8000;

Beyond that, compare the listen directive to that in your other server blocks - make sure it matches. If they're bound to a specific address instead of 0.0.0.0, then this server wouldn't be getting the requests.

edit:

For those who find this question in the future, the subdomain's server block was not being included - and the include block must be within the existing http block to avoid address binding conflicts.

share|improve this answer
    
I added the http:// to subdomain.domain.tld.conf. In /opt/nginx/conf/nginx.conf, the normal server for domain.tld listens on just "80", would that cause it to not send the request? I need the normal server to listen on port 80 too though, since it needs to serve domain.tld. –  Archio Jan 18 '12 at 1:02
    
Also, I checked both the nginx error and access logs, found nothing. It seems the issue is that the subdomain is getting served to nginx.conf instead of my specific subdomain conf file. –  Archio Jan 18 '12 at 1:06
1  
@Archio That ought to work fine, as listen 0.0.0.0:80 is functionally equivilent to listen 80, at least as far as IPv4 is concerned, but go ahead and change them to match - can't hurt. Can you verify that there's an include in the main config pointing to the sites-enabled directory? –  Shane Madden Jan 18 '12 at 1:07
    
Good call, it wasn't... but now that I included it, it's warning me that 0.0.0.0:80 is already in use. In other words, it's not letting me bind subdomain.domain.tld to 80 because domain.tld is already using it, I think. –  Archio Jan 18 '12 at 1:28
1  
Strange.. as a sanity check, maybe just check lsof -i -P | grep 80 while nginx is stopped? –  Shane Madden Jan 18 '12 at 1:58

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.