首页 > 解决方案 > /etc/nginx/sites-enabled/default 错误中 0.0.0.0:80 的重复默认服务器在哪里重复?

问题描述

我想我可能脑子有问题,但解决方案现在正在逃避我。启动时,Nginx 在 journalctl 中返回以下错误。

“/etc/nginx/sites-enabled/default 中 0.0.0.0:80 的重复默认服务器”

我看不到默认的副本。这是我启用站点的默认文件,其他任何人都可以指出错误的原因吗?

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;
}


}


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

server_name demo4.review;

root /var/www/static;
index index.html;

location / {
    try_files $uri $uri/ =404;
}
}

server {

    server_name wp.demo4.review;

    root /var/www/wp_demo;

      location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
            # This is cool because no php is touched for static content.
            # include the "?$args" part so non-default permalinks doesn't break when using query string
            try_files $uri $uri/ /index.php?$args;
    }

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

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }



listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/wp.demo4.review/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/wp.demo4.review/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = wp.demo4.review) {
    return 301 https://$host$request_uri;
} # managed by Certbot


    listen 80;
    listen [::]:80;

    server_name wp.demo4.review;
return 404; # managed by Certbot


}
server {
listen 80;
    server_name api.demo4.review;
location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
}



server {
if ($host = wp.demo4.review) {
    return 301 https://$host$request_uri;
} # managed by Certbot



    server_name wp.demo4.review;
listen 80;
return 404; # managed by Certbot


}


server {

    server_name ukl.demo4.review;

    root /var/www/ukl;

   ## This should be in your http block and if it is, it's not needed here.
    index index.php;

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

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

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

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }



listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ukl.demo4.review/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ukl.demo4.review/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}

server {
if ($host = ukl.demo4.review) {
    return 301 https://$host$request_uri;
} # managed by Certbot



    server_name ukl.demo4.review;
listen 80;
return 404; # managed by Certbot


}

标签: nginxnginx-config

解决方案


在 Nginx 也在读取的同一目录中有一个 default.save 文件。


推荐阅读