1

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()
1

1 Answer 1

1

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.

15
  • 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.
    – element119
    Jan 18, 2012 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.
    – element119
    Jan 18, 2012 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? Jan 18, 2012 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.
    – element119
    Jan 18, 2012 at 1:28
  • 1
    Strange.. as a sanity check, maybe just check lsof -i -P | grep 80 while nginx is stopped? Jan 18, 2012 at 1:58

You must log in to answer this question.

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