0

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?

2
  • 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, 2013 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. May 12, 2013 at 3:38

2 Answers 2

2

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

1
  • do you have to write listen: 8080 in every domain conf file? I tried to set that only in sites-enabled/default or conf.d/default.conf but didn't work. Jul 2, 2015 at 2:30
-2

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

nginx -s reload
1
  • I tried reloading it like you've said and it still doesn't work.
    – moka
    May 4, 2013 at 19:31

You must log in to answer this question.

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