Nginx:[警告]在0.0.0.0:80上冲突的服务器名称“non.com”,被忽略

问题描述 投票:1回答:2

我在我的Ubuntu 14.04 VPS上运行了一个node.js应用程序。一切都已建立,从dns到Cloudfare,再到pm2运行应用程序。

我遇到了与冲突的Nginx配置文件有问题。我是这一切的新手,所以我不知道它是如何100%工作的。

进行一些谷歌搜索告诉我,通过使用纳米编辑器,可能有.save文件,使它发生冲突,我检查,事实并非如此。虽然,我在/nginx/sites-available//nginx/sites-enabled/中有相同的文件。

这是一个名为default的文件:

server {
    listen 80;

    server_name domainName.com;

    location / {
        proxy_pass http://MY-IP: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;
    }
}

每当我重新启动nginx时,我都会收到警告nginx: [warn] conflicting server name "domainName.com" on 0.0.0.0:80, ignored

这是我的nginx.conf文件:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    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;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

ls -al /etc/nginx/sites-enabled的输出:

total 8
drwxr-xr-x 2 root root 4096 Aug 28 07:33 .
drwxr-xr-x 5 root root 4096 Aug 28 07:33 ..
lrwxrwxrwx 1 root root   34 Aug 28 07:33 default -> /etc/nginx/sites-available/default

ls -alh /etc/nginx/conf.d/的输出:

total 8.0K
drwxr-xr-x 2 root root 4.0K Jul 12 06:35 .
drwxr-xr-x 5 root root 4.0K Aug 28 07:33 ..

我不知道还能做什么,任何帮助都会受到赞赏。

node.js ubuntu nginx vps
2个回答
1
投票

为了解决我的问题,我在proxy_pass http://MY-IP:3000/;上将proxy_pass http://localhost:3000/;更改为/etc/nginx/sites-available/default

然后我使用sudo service apache2 stop停止了Apache2,用sudo service nginx restart重新启动了nginx,所有工作都非常好。

显然我使用的是我的VPS的IP而不是使用localhost作为地址。


0
投票

一旦你确认domainName.com没有在你的Nginx配置中的任何其他地方的server_name中使用,请查找$hostname或其他Nginx变量,其值可能与你的server_name匹配:

Alphabetical index of Nginx variables

例:

server {
    server_name localhost $hostname;
    listen 80;

    access_log off;
}

让我困惑了一段时间。

© www.soinside.com 2019 - 2024. All rights reserved.