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'm really hoping someone can help me with this. After a lot of searching I haven't been able to find the solution.

I am running my website on NGINX and have Varnish enabled however, when I try to redirect the www version of my domain to the non-www version, it doesn't work and I've tried quite a few different methods.

Here is my configuration file at the moment:

server {
    server_name ~^(.+\.)(?<domain>.+\..+)$;
    rewrite ^ $scheme://domain.com permanent;
}

server {
    listen 8080;
    listen [::]:8080 ipv6only=on default_server;

...
..
.
}

When I try to restart NGINX though I get the following error:

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

Anyone know what's up?

share|improve this question
    
You probably ought to post the rest of your config file. Also does Nginx start up without errors on system boot up? –  Danack May 5 '13 at 13:14
    
Your error "Address already in use" is likely because you have two listen directives, why do you need both? Also check your logs for more information. –  Drew Khoury May 12 '13 at 3:38

2 Answers 2

up vote 0 down vote accepted

You have not set 'listen' parameter for first 'server' (with redirect).

Nginx listens on *:80 by default (when run from superuser), or *:8000 (when run from regular user).

80 port already binded by Varnish. So, you just need to set 'listen 8080;' for all 'servers' you have to prevent binding to default port

share|improve this answer
    
Excellent! This worked, thank you very much. –  moka May 16 '13 at 10:26

Why are you restarting Nginx? It supports a reload of a config file:

nginx -s reload
share|improve this answer
    
I tried reloading it like you've said and it still doesn't work. –  moka May 4 '13 at 19:31

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.