L
L
Lelouch2016-07-16 17:49:48
Nginx
Lelouch, 2016-07-16 17:49:48

Why does nginx complain about a server name conflict?

I decided to learn nginx and migrated my sites to it from Apache.
Please help me figure out why I'm getting a warning on the command:
nginx -t

nginx: [warn] conflicting server name "" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "" on [::]:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

As far as I understand I don't have overlapping server names. config :
site1:
server {
  listen 80;
  listen [::]:80;

  server_name www.site1.ru site1.ru;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  include snippets/ssl-site1.ru.conf;
  include snippets/ssl-params.conf;

  autoindex off;
  index index.php index.html;
  fastcgi_index index.php;
  root /var/www/ipprosto.ru/html;
  access_log /var/www/site1.ru.access.log;
  error_log /var/www/site1.ru.error.log;

  location / {
#		location ~ [^/]\.ph(p\d*|tml)$ {
#			try_files /does_not_exists @php;
#		}
#		try_files $uri $uri/ $uri.php?$args;
#		index index.php index.html index.htm;
    try_files $uri $uri/ /index.php$is_args$args;
#		try_files $uri $uri/ /index.php?$args;
  }

#	location @php {
#		fastcgi_index index.php;
#		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
#		try_files $uri =404;
#		include fastcgi_params;
#	}

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
  
  location = /favicon.ico {
    log_not_found off;
    access_log off;
  }
  
#	location = /robots.txt {
#		log_not_found off;
#		access_log off;
#		allow all;
#	}
  
  location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    expires max;
    log_not_found off;
  }
  
  location ~ /.well-known {
    allow all;
  }

}

site2:
server {
  listen 80;
  listen [::]:80;

  server_name site2.ru;
  return 301 https://$server_name$request_uri;
}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  include snippets/ssl-site2.ru.conf;
  include snippets/ssl-params.conf;

  autoindex off;
  index index.php index.html;
  fastcgi_index index.php;
  root /var/www/site2.ru/html;
  access_log /var/www/site2.ru.access.log;
  error_log /var/www/site2.ru.error.log;

  location / {
    location ~ [^/]\.ph(p\d*|tml)$ {
       try_files /does_not_exists @php;
    }
    try_files $uri $uri/ $uri.php?$args;
  }

  location @php {
    fastcgi_index index.php;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
    try_files $uri =404;
    include fastcgi_params;
  }

  location /l/ {
    rewrite ^/l/([a-zA-Z0-9/]+)$ /l.php?i=$1 last;
  }

  location /t/ {
    rewrite ^/t/([a-zA-Z0-9/]+)$ /t.php?i=$1 last;
  }

  location /w/ {
    rewrite ^/w/([a-zA-Z0-9/]+)$ /w.php?i=$1 last;
  }

  location /unsubscribe/ {
    rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last;
  }

  location /subscribe/ {
    rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 last;
  }

  location ~ /.well-known {
    allow all;
  }

  location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
    access_log off;
    log_not_found off;
    expires 30d;
  }
}

default:
server {
  listen 80 default_server;
  listen [::]:80 default_server;

  root /var/www/html;

  index index.html index.htm index.nginx-debian.html;

  server_name _;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
  }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cool Admin, 2016-07-16
@Lelouch

Your server_name port is not set for the server directive on 443, so nginx considers it = "" (empty), and swears at it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question