我的 Ubuntu 14.04 VPS 上运行着一个 node.js 应用程序。 一切都已设置完毕,从 DNS 通过 Cloudfare 到使用 pm2 运行应用程序。
我遇到了 Nginx 配置文件冲突的问题。 我对这一切都很陌生,所以我不知道它是如何 100% 工作的。
进行一些谷歌搜索后,我发现通过使用 Nano 编辑器可能会出现 .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 ..
我不知道还能做什么,任何帮助将不胜感激。
最佳答案
为了解决我的问题,我将 /etc/nginx/sites-available/default
上的 proxy_pass http://MY-IP:3000/;
更改为 proxy_pass http://localhost:3000/;
。
然后我使用 sudo service apache2 stop
停止了 Apache2,使用 sudo service nginx restart
重新启动了 nginx,一切都工作得很好。
显然我使用的是我的 VPS 的 IP,而不是使用 localhost 作为地址。
关于node.js - Nginx:[警告] 0.0.0.0:80 上的冲突服务器名称 "non.com",已忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45917436/