nginx vhost 错误“重复的默认服务器”

nginx vhost 错误“重复的默认服务器”

我在已设置的 CentOS 7 机器上设置基于名称的虚拟主机时遇到问题。当我尝试启动时,出现以下错误:

12 月 07 日 20:55:28 li805-37 nginx[7284]: nginx: [emerg] /etc/nginx/conf.d/website-one.conf:2 中的 0.0.0.0:80 的重复默认服务器

以下是/etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" 

'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    include /etc/nginx/conf.d/*.conf;
}

以及 vhost 配置,首先website-one运行节点:

upstream node_server {
   server 127.0.0.1:3000 fail_timeout=0;
}

server {
    listen 80;
    server_name website-one.com;

    index index.html index.htm;
    access_log /var/log/webone/access.log;
    error_log /var/log/webone/error.log debug;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_redirect off;
        proxy_buffering off;
        proxy_pass http://node_server;
    }

    location /public/ {
        root /opt/website-one;
    }
}

那么website-two目前这是一个静态 html 站点:

server {
    listen 80;
    server_name website-two.com;

    access_log /var/log/webtwo/access.log;
    error_log /var/log/webtwo/error.log debug;
    index index.php index.html index.htm;

    location / {
        root /var/www/;
    }

}

另外,我尝试在/etc/nginx目录中搜索“default_server”,结果只找到两行注释掉的行,/etc/nginx/nginx.con为了简洁起见,我已将其删除。

答案1

这完全是我的一个想法。首先,我尝试启动 nginx,如下所示:

sudo systemctl start nginx.service

当它失败时我检查了错误消息:

sudo systemctl status -l nginx.service

然后,在我修复了问题之后,我再次运行查看错误是否仍然存在sudo systemctl status -l nginx.service,但没有尝试启动服务,该命令只给了我最后一个错误!因此,尽管已经修复了问题,但我还是得到了同样的错误。记住,当更改 nginx 配置时,你必须实际启动服务在检查错误消息之前。

相关内容