Home > Enterprise >  nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored

Time:10-31

I have three nginx server blocks and when i run nginx -t get error "nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored"

I have three nginx server blocks:

One: /etc/nginx/sites-available/default

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

        root /var/www/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;
        }

}

Two: /etc/nginx/sites-available/example.com

server {
    listen         80;
    return 301 https://$host$request_uri;
}
server {
# Document Root
root /var/www/example.com;
index index.php index.html index.htm;
server_name .example.com;
client_max_body_size 0;

    listen [::]:443 ssl http2 ipv6only=on;
    listen 443 ssl http2;
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        ssl_prefer_server_ciphers on;
        ssl_session_cache   shared:SSL:20m;
        ssl_session_timeout 20m;
        ssl_ciphers 'TLS13 AESGCM AES128:EECDH AES128';


error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

# Rocket-Nginx configuration
  include rocket-nginx/conf.d/default.conf;

# security
    include             nginxconfig.io/security.conf;

# Block XMLRPC
location = /xmlrpc.php {
    deny all;
}

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~* \.php$ {
if ($uri !~ "^/uploads/") {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
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|svg|ico|woff2|eot|jpeg|webp|jpg|js|png)$ {
expires 1y;
log_not_found off;
}

# Enable Gzip compression.
gzip on;

# Disable Gzip on IE6.
gzip_disable "msie6";

# Allow proxies to cache both compressed and regular version of file.
# Avoids clients that don't support Gzip outputting gibberish.
gzip_vary on;

# Compress data, even when the client connects through a proxy.
gzip_proxied any;

# The level of compression to apply to files. A higher compression level increases
# CPU usage. Level 5 is a happy medium resulting in roughly 75% compression.
gzip_comp_level 5;

# Compress the following MIME types.
gzip_types
 application/atom xml
 application/javascript
 application/json
 application/ld json
 application/manifest json
 application/rss xml
 application/vnd.geo json
 application/vnd.ms-fontobject
 application/x-font-ttf
 application/x-web-app-manifest json
 application/xhtml xml
 application/xml
 font/opentype
 image/bmp
 image/svg xml
 image/x-icon
 text/cache-manifest
 text/css
 text/plain
 text/vcard
 text/vnd.rim.location.xloc
 text/vtt
 text/x-component
 text/x-cross-domain-policy;
}

Three: /etc/nginx/sites-available/example1.com

server {
    listen         80;
    return 301 https://$host$request_uri;
}
server {
# Document Root
root /var/www/example1.com;
index index.php index.html index.htm;
server_name .example1.com;
client_max_body_size 0;

    listen [::]:443 ssl http2;
    listen 443 ssl http2;
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_certificate /etc/letsencrypt/live/example1.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example1.com/privkey.pem;
        ssl_prefer_server_ciphers on;
        ssl_session_cache   shared:SSL:20m;
        ssl_session_timeout 20m;
        ssl_ciphers 'TLS13 AESGCM AES128:EECDH AES128';


error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

# Rocket-Nginx configuration
  include rocket-nginx/conf.d/default.conf;

# security
    include             nginxconfig.io/security.conf;

# Block XMLRPC
location = /xmlrpc.php {
    deny all;
}

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~* \.php$ {
if ($uri !~ "^/uploads/") {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
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|svg|ico|woff2|eot|jpeg|webp|jpg|js|png)$ {
expires 1y;
log_not_found off;
}

# Enable Gzip compression.
gzip on;

# Disable Gzip on IE6.
gzip_disable "msie6";

# Allow proxies to cache both compressed and regular version of file.
# Avoids clients that don't support Gzip outputting gibberish.
gzip_vary on;

# Compress data, even when the client connects through a proxy.
gzip_proxied any;

# The level of compression to apply to files. A higher compression level increases
# CPU usage. Level 5 is a happy medium resulting in roughly 75% compression.
gzip_comp_level 5;

# Compress the following MIME types.
gzip_types
 application/atom xml
 application/javascript
 application/json
 application/ld json
 application/manifest json
 application/rss xml
 application/vnd.geo json
 application/vnd.ms-fontobject
 application/x-font-ttf
 application/x-web-app-manifest json
 application/xhtml xml
 application/xml
 font/opentype
 image/bmp
 image/svg xml
 image/x-icon
 text/cache-manifest
 text/css
 text/plain
 text/vcard
 text/vnd.rim.location.xloc
 text/vtt
 text/x-component
 text/x-cross-domain-policy;
}

When i run: $ sudo nginx -t

This answer appears:

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

How do i solve this?

CodePudding user response:

example.com and example1.com both are identical, you have to add server_name on the listen 80 of both blocks.

Corrected Server blocks is:

Two: /etc/nginx/sites-available/example.com

server {
    listen         80;
    server_name .example.com;
    return 301 https://example.com$request_uri;
}
server {
# Document Root
root /var/www/example.com;
index index.php index.html index.htm;
server_name .example.com;
client_max_body_size 0;

    listen [::]:443 ssl http2 ipv6only=on;
    listen 443 ssl http2;
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        ssl_prefer_server_ciphers on;
        ssl_session_cache   shared:SSL:20m;
        ssl_session_timeout 20m;
        ssl_ciphers 'TLS13 AESGCM AES128:EECDH AES128';


error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

# Rocket-Nginx configuration
  include rocket-nginx/conf.d/default.conf;

# security
    include             nginxconfig.io/security.conf;

# Block XMLRPC
location = /xmlrpc.php {
    deny all;
}

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~* \.php$ {
if ($uri !~ "^/uploads/") {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
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|svg|ico|woff2|eot|jpeg|webp|jpg|js|png)$ {
expires 1y;
log_not_found off;
}

# Enable Gzip compression.
gzip on;

# Disable Gzip on IE6.
gzip_disable "msie6";

# Allow proxies to cache both compressed and regular version of file.
# Avoids clients that don't support Gzip outputting gibberish.
gzip_vary on;

# Compress data, even when the client connects through a proxy.
gzip_proxied any;

# The level of compression to apply to files. A higher compression level increases
# CPU usage. Level 5 is a happy medium resulting in roughly 75% compression.
gzip_comp_level 5;

# Compress the following MIME types.
gzip_types
 application/atom xml
 application/javascript
 application/json
 application/ld json
 application/manifest json
 application/rss xml
 application/vnd.geo json
 application/vnd.ms-fontobject
 application/x-font-ttf
 application/x-web-app-manifest json
 application/xhtml xml
 application/xml
 font/opentype
 image/bmp
 image/svg xml
 image/x-icon
 text/cache-manifest
 text/css
 text/plain
 text/vcard
 text/vnd.rim.location.xloc
 text/vtt
 text/x-component
 text/x-cross-domain-poli
}

Three: /etc/nginx/sites-available/example1.com

server {
    listen         80;
server_name .example1.com;
    return 301 https://example1.com$request_uri;
}
server {
# Document Root
root /var/www/example1.com;
index index.php index.html index.htm;
server_name .example1.com;
client_max_body_size 0;

    listen [::]:443 ssl http2;
    listen 443 ssl http2;
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_certificate /etc/letsencrypt/live/example1.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example1.com/privkey.pem;
        ssl_prefer_server_ciphers on;
        ssl_session_cache   shared:SSL:20m;
        ssl_session_timeout 20m;
        ssl_ciphers 'TLS13 AESGCM AES128:EECDH AES128';


error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

# Rocket-Nginx configuration
  include rocket-nginx/conf.d/default.conf;

# security
    include             nginxconfig.io/security.conf;

# Block XMLRPC
location = /xmlrpc.php {
    deny all;
}

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~* \.php$ {
if ($uri !~ "^/uploads/") {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
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|svg|ico|woff2|eot|jpeg|webp|jpg|js|png)$ {
expires 1y;
log_not_found off;
}

# Enable Gzip compression.
gzip on;

# Disable Gzip on IE6.
gzip_disable "msie6";

# Allow proxies to cache both compressed and regular version of file.
# Avoids clients that don't support Gzip outputting gibberish.
gzip_vary on;

# Compress data, even when the client connects through a proxy.
gzip_proxied any;

# The level of compression to apply to files. A higher compression level increases
# CPU usage. Level 5 is a happy medium resulting in roughly 75% compression.
gzip_comp_level 5;

# Compress the following MIME types.
gzip_types
 application/atom xml
 application/javascript
 application/json
 application/ld json
 application/manifest json
 application/rss xml
 application/vnd.geo json
 application/vnd.ms-fontobject
 application/x-font-ttf
 application/x-web-app-manifest json
 application/xhtml xml
 application/xml
 font/opentype
 image/bmp
 image/svg xml
 image/x-icon
 text/cache-manifest
 text/css
 text/plain
 text/vcard
 text/vnd.rim.location.xloc
 text/vtt
 text/x-component
 text/x-cross-domain-policy;
}

no need to do changes on default one.

  • Related