4

I'm using Debian, most recent dotdeb nginx-lite. I've read that the first server section found by nginx will be used as the fallback/default section used if there is no specific server section for a domain.

I deleted sites-available and sites-enabled from my installation because I use a dedicated mount /www for everything http related.

My /etc/nginx/nginx.conf has these lines including other confs:

    include /www/conf.d/nginx/default.conf;
    include /etc/nginx/conf.d/*.conf;
    include /www/conf.d/nginx/*;

default.conf looks like:

server {
        server_name 0.0.0.0;
        listen 0.0.0.0:80;
        rewrite ^ http://mymaintarget.com permanent;
}

This does not work for me. I still get this warning:

Restarting nginx: nginxnginx: [warn] conflicting
server name "0.0.0.0" on 0.0.0.0:80, ignored

Im pretty sure there is no other server section and default.conf is the first one included / used.

Anybody knows what's wrong or how the correct way of configuring a default server is?

Update full config files:

nginx.conf:

user www-data;
worker_processes 8;
pid /run/nginx.pid;

events {
        worker_connections 768;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 10;
        types_hash_max_size 2048;
        server_tokens off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        error_log /var/log/nginx/error.log;

        gzip on;
        gzip_disable "msie6";
        gzip_vary on;


        # Default VirtualHost
        include /www/conf.d/nginx/default.conf;

        # conf.d is empty anyways
        #include /etc/nginx/conf.d/*.conf;

        # VirtualHosts
        include /www/conf.d/nginx/*;
}

default.conf:

server {
        listen 80 default_server;
        rewrite ^ http://blog.flowl.info permanent;
}
2
  • remove that server_name clause or simply add the hostname itself - not an IP address, hence the name ;-)
    – vautee
    Feb 24, 2014 at 12:44
  • @vautee tried, it still claims the same error
    – Daniel W.
    Feb 24, 2014 at 13:01

2 Answers 2

6

To set a default server:

server {
    listen 80 default_server;
    rewrite ^ http://mymaintarget.com$request_uri? permanent;
}

The default_server parameter will include any other domain, ip etc

More info nginx

5
  • 1
    I get nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /www/conf.d/nginx/default.conf:3 ... I used grep to check for files containing default, and got none. I don't have any other servers defined besides my /www/conf folder...
    – Daniel W.
    Feb 24, 2014 at 12:58
  • Please show us your whole configuration file, there must be a conflict somewhere
    – krokola
    Feb 24, 2014 at 12:59
  • updated the question
    – Daniel W.
    Feb 24, 2014 at 13:04
  • Show also any configuration file that in into /www/conf.d/nginx/*
    – krokola
    Feb 24, 2014 at 13:06
  • AHHHH LOL, I include the dafault.conf twice, first directly, and second with /* ...
    – Daniel W.
    Feb 24, 2014 at 13:06
1
    # Default VirtualHost
    include /www/conf.d/nginx/default.conf;

    # conf.d is empty anyways
    #include /etc/nginx/conf.d/*.conf;

    # VirtualHosts
    include /www/conf.d/nginx/*;

"default.conf" gets included, and then gets included again in /www/conf.d/nginx/*

I removed the first include, and renamed "default.conf" to "_default.conf" so the file is the first to be included in the wildcard include.

You must log in to answer this question.

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