Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#1704 closed defect (invalid)

Nginx should have a friendly notice when config file have same port and same server_name

Reported by: dannyZhou@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.14.x
Keywords: Cc:
uname -a: Linux archlinux 4.14.90-1-lts #1 SMP Fri Dec 21 15:53:10 CET 2018 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.14.2
built with OpenSSL 1.1.1a 20 Nov 2018
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/bin/nginx --pid-path=/run/nginx.pid --lock-path=/run/lock/nginx.lock --user=http --group=http --http-log-path=/var/log/nginx/access.log --error-log-path=stderr --http-client-body-temp-path=/var/lib/nginx/client-body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-cc-opt='-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2' --with-ld-opt=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now --with-compat --with-debug --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-pcre-jit --with-stream --with-stream_geoip_module --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads

Description

nginx.conf to reproduce.

http { 
  server {
    listen 80;
    server_name localhost;
    location / {
      root /var/www1;
    }
  }
  server {
    listen 80;
    server_name localhost;
    location / {
      root /var/www2;
    }
  }
}

Two server blocks with same listen port and same server_name;

$ sudo nginx -t
2019/01/09 09:41:06 [warn] 9076#9076: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
2019/01/09 09:41:06 [warn] 9076#9076: conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# danny @ archlinux in ~/tmp/tmp [9:41:06] 
$ sudo nginx -s reload
2019/01/09 09:41:15 [warn] 9084#9084: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
2019/01/09 09:41:15 [warn] 9084#9084: conflicting server name "localhost" on 0.0.0.0:80, ignored
2019/01/09 09:41:15 [notice] 9084#9084: signal process started

A better log should tell us have same port and server_name config.

Sorry my English is poor.

Change History (2)

comment:1 by Maxim Dounin, 6 years ago

Resolution: invalid
Status: newclosed

The message says:

[warn] ... conflicting server name "localhost" on 0.0.0.0:80, ignored

which clearly warns about conflicting server name, and lists both server name in question and listening IP/port, as well as action taken. I don't think this can be improved.

comment:2 by dannyZhou@…, 6 years ago

Sorry it's my fault.
English is poor.

Note: See TracTickets for help on using tickets.