[英]Nginx configuration on a centos 6.7
Im working on a centos 6.7 machine and I'm trying to configure nginx to serve a node.js application. 我正在使用centos 6.7机器,我正在尝试配置nginx来为node.js应用程序提供服务。 I feel like I'm really close but I'm missing something. 我觉得我很亲密,但我错过了一些东西。 So heres my nginx.conf and below that is my server.conf thats in my sites-enabled directory. 所以继承人我的nginx.conf及其下面是我的server.conf,它位于我的启用站点的目录中。
When I go to the public IP address it gives me a 502 bad gateway error. 当我转到公共IP地址时,它给我一个502错误的网关错误。 But if I curl the private IP with the correct port on my centos machine I can see the node application running. 但是,如果我使用centos机器上的正确端口卷曲私有IP,我可以看到节点应用程序正在运行。 What am I missing here? 我在这里错过了什么? is it a firewall issue or maybe something else? 它是防火墙问题还是别的什么?
nginx.conf 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/*;
}
sites-enabled/server.conf 启用站点-/ 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;
}
}
UPDATE: I figured this out! 更新:我想出来了! heres the server block that worked for me 继承了对我有用的服务器块
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 {
}
}
I want to write a comment but stack overflow does not let me do it. 我想写一个评论,但堆栈溢出不允许我这样做。
I am 99% sure that Node.js website does NOT need to work with nginx or apache. 我99%肯定Node.js的网站不需要与nginx的或Apache工作。
If the script setup correctly, the Node.js Application should listen to the port by itself. 如果脚本设置正确,Node.js应用程序应该自己监听端口。
Since you did not really say much of your structure, I guess you can just try to access through the public IP with the port of Node.js. 由于你没有真正说出你的结构,我想你可以尝试使用Node.js端口通过公共IP访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.