我正在使用centos 6.7机器,我正在尝试配置nginx来为node.js应用程序提供服务 . 我觉得我很亲密,但我错过了一些东西 . 所以继承人我的nginx.conf及其下面是我的server.conf,它位于我的启用站点的目录中 .
当我转到公共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 {
}
}
1 回答
我想写一个评论,但堆栈溢出不允许我这样做 .
我99%确定Node.js网站确实 NOT 需要使用nginx或apache .
如果脚本设置正确,Node.js应用程序应该自己监听端口 .
由于你没有真正说出你的结构,我想你可以尝试使用Node.js端口通过公共IP访问 .