1
我在一個centos 6.7機器上工作,我試圖配置nginx來爲node.js應用程序提供服務。我覺得我很親密,但我錯過了一些東西。所以繼承人我的nginx.conf和下面是我的server.conf這是在我的網站啓用目錄。一個centos上的Nginx配置6.7
當我轉到公共IP地址時,它給我一個502錯誤的網關錯誤。但是如果我使用我的centos機器上的正確端口來捲曲私有IP,我可以看到節點應用程序正在運行。我在這裏錯過了什麼?這是一個防火牆問題還是別的什麼?
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
keepalive_timeout 65;
#gzip on;
#include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
網站啓用/ server.conf中
server {
listen 80;
#server_name localhost;
location/{
proxy_pass http://192.xxx.x.xx:8000; // private IP
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 {
listen 80 default_server;
listen [::]:80 default_server;
#server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location/{
proxy_pass http://127.0.0.1:9000;
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;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}