我在我的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 ..
我不知道还能做什么,任何帮助都会受到赞赏。
为了解决我的问题,我在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作为地址。
一旦你确认domainName.com
没有在你的Nginx配置中的任何其他地方的server_name
中使用,请查找$hostname
或其他Nginx变量,其值可能与你的server_name
匹配:
Alphabetical index of Nginx variables
例:
server {
server_name localhost $hostname;
listen 80;
access_log off;
}
让我困惑了一段时间。