gpt4 book ai didi

linux - centos 6.7 上的 Nginx 配置

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:25:08 25 4
gpt4 key购买 nike

我在 centos 6.7 机器上工作,我正在尝试配置 nginx 来为 node.js 应用程序提供服务。我觉得我真的很接近,但我错过了一些东西。所以这是我的 nginx.conf,下面是我的 server.conf,位于我的启用站点的目录中。

当我转到公共(public) IP 地址时,它给我一个 502 错误的网关错误。但是,如果我在我的 centos 机器上使用正确的端口 curl 私有(private) IP,我可以看到 Node 应用程序正在运行。我在这里错过了什么?是防火墙问题还是其他原因?

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;
}
}

更新:我想通了!这是对我有用的服务器 block

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 {
}
}

最佳答案

我想写评论,但堆栈溢出不允许我这样做。

我 99% 确定 Node.js 网站不需要需要与 nginx 或 apache 一起工作。

如果脚本设置正确,Node.js 应用程序应该自己监听端口。

由于你并没有真正说出你的结构,我想你可以尝试使用Node.js的端口通过公共(public)IP访问。

关于linux - centos 6.7 上的 Nginx 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36432713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com