gpt4 book ai didi

Node.js+Nginx 抛出 502 bad gateway 错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:45:45 30 4
gpt4 key购买 nike

我刚刚将 Node.js 应用程序安装到开发环境中。配置是:乌类图16.xPHP 7.0Node.js 8.xmysqlphpMyAdminnginx

我的 Node 应用程序使用端口 2000,子文件夹名称为 nodeapp。尽管 phpmyadmin 正常打开,但 Node 应用程序给出 502 Bad gateway。

这是 nginxconf 文件:

server {
listen 80 default_server;
listen [::]:80 default_server;
listen 2000;

root /home/pjsp/public_html;
index index.php index.html index.htm index.nginx-debian.html app.js;

server_name mydomain.com;

location /nodeapp {
proxy_pass http://localhost/nodeapp:2000;
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;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
deny all;
}

}

下面是我在/var/log/nginx/error.log 文件中遇到的错误:

2018/06/02 13:13:15 [error] 32209#32209: *763 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: mydomain.com, request: "GET /nodeapp:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000

请帮忙!

Update:

新配置文件:

server {
listen 80 default_server;
listen [::]:80 default_server;
#listen 2000;

root /home/pjsp/public_html;
index index.php index.html index.htm index.nginx-debian.html app.js;

server_name app.pajasa.com www.app.pajasa.com;

location /nodeapp {
proxy_pass http://localhost;
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;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
deny all;
}

}

现在出现错误:

2018/06/02 14:52:35 [alert] 3026#3026: *765 768 worker_connections are not enough while connecting to upstream, client: 127.0.0.1, server: app.pajasa.com, request: "GET /nodeapp:2000 HTTP/1.1", upstream: "http://127.0.0.1:80/nodeapp:2000", host: "www.app.pajasa.com"

网址:www.app.pajasa.com/nodeapp:2000

最佳答案

你的 nginx 中有一个无限循环。这就是为什么你会看到:

/nodeapp:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000:2000....

如果您的 Node 应用程序正在监听端口 2000,请不要在 Nnginx 上使用 listen 2000;

删除该请求后,请求:http://localhost/nodeapp 将传递到您的 Node 应用程序上。

此外,您的 proxy_pass 不正确,应该是:

 proxy_pass http://localhost:2000;

更新

您的网址错误

www.app.pajasa.com/nodeapp:2000 // INCORRECT

首先,正如我们已经提到的,如果您使用 Nginx 代理 Node.js 应用程序,则不必在 URL 上添加端口,其次,更重要的是,这不是端口的工作方式:

www.app.pajasa.com:2000 // This is correct

从 URL 中删除 :2000,Nginx 会将其代理到您的 Node 应用程序。

www.app.pajasa.com/nodeapp

关于Node.js+Nginx 抛出 502 bad gateway 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50657315/

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