WebSocket ws nginx 反向代理 502 坏网关
WebSocket ws nginx reverse proxy 502 bad gateway
我知道互联网上有很多不同的主题对此很感兴趣,其中很多像我一样开始但真正困难的主题
我有一个 nodejs 应用程序,它有两种不同的工作方式
1. 适用于端口 3000 和 2. 适用于 api。在端口 3001 上我还在端口 3001 上使用 WebSocket 进行一些管理操作,无论如何我在本地环境中没有任何问题。我将项目部署到 digitalocean 它是一个很好的工作环境和我的 nginx 设置如下
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 188.166.91.39;
return 302 https://8.166.91.39$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
server_name 188.166.91.39;
gzip on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types application/x-javascript application/javascript application/xml application/json text/xml text/css text$
client_body_timeout 12;
client_header_timeout 12;
reset_timedout_connection on;
send_timeout 10;
server_tokens off;
client_max_body_size 50m;
expires 1y;
access_log off;
log_not_found off;
root /var/www/prtzn/public/content;
location ~ "^/images/(?<entity>\w+)/(?<id>\w+)/(?<width>[1-9][0-9][0-9]{1}|[1][0-9][0-9][0-9]{1})/(?<file>.+)$" {
# /images/products/id/100/file.jpg >>> Proxy to internal image resizing server
proxy_pass http://127.0.0.1:8888/resize/$entity/$id/$width/$file;
proxy_cache images;
proxy_cache_valid 200 30d;
}
location /assets/ {
alias /var/www/prtzn/theme/assets/;
}
location /sw.js {
root /var/www/prtzn/theme/assets/;
}
location ~ ^/(api|ajax|ws|images)/ {
# Proxy to NodeJS
expires off;
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
try_files $uri @proxy;
}
location @proxy {
# Proxy to NodeJS
expires off;
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
我遵循了 digitalocean 的说明,它们真的很好我已经安装了应用程序但是我的 https 前端出现 502 Bad Gateway 错误。它试图连接并想要握手,但无法做到。给出这样的错误
wsUrl..: wss://188.166.91.39
app-0c847e67113cfb2f2a2f.js:1 WebSocket connection to
'wss://188.166.91.39/ws/dashboard?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZXMiOlsiYWRtaW4iXSwianRpIjoiNWM2YzUyNDNhY2ZmMzgyZGFhZDZiZGNhIiwiZW1haWwiOiJoYW1pdC55aWxkaXJpbS41ODM0QGdtYWlsLmNvbSIsImlhdCI6MTU1MTA0NzI5MiwiZXhwIjoxNTUxMzA2NDkyfQ.AQ96n9cT0Ntab3GqYT-bFbhRlAyZj3tL53K9QjzEonM'
failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
也许这对你来说会变得非常简单易懂,但我对这类作品不是很有经验,我无法理解这是来自 faint token 还是 nginx 配置,或者是否还有其他错误配置
我的应用程序 运行 pm2 然后我不看 pm2 命令的日志经过一些研究我注意到我的网络 api 不能正常工作,命令无法看到
npm start process.json
因为我的 2 个应用程序正在运行并且在线,但其中一个应用程序没有使用任何内存,所以在注意到我已经尝试
至:
npm 开始
我还看到了其他错误。我修好了地雷。真正的错误是后端服务不是运行或没有响应
我知道互联网上有很多不同的主题对此很感兴趣,其中很多像我一样开始但真正困难的主题 我有一个 nodejs 应用程序,它有两种不同的工作方式 1. 适用于端口 3000 和 2. 适用于 api。在端口 3001 上我还在端口 3001 上使用 WebSocket 进行一些管理操作,无论如何我在本地环境中没有任何问题。我将项目部署到 digitalocean 它是一个很好的工作环境和我的 nginx 设置如下
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 188.166.91.39;
return 302 https://8.166.91.39$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
server_name 188.166.91.39;
gzip on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types application/x-javascript application/javascript application/xml application/json text/xml text/css text$
client_body_timeout 12;
client_header_timeout 12;
reset_timedout_connection on;
send_timeout 10;
server_tokens off;
client_max_body_size 50m;
expires 1y;
access_log off;
log_not_found off;
root /var/www/prtzn/public/content;
location ~ "^/images/(?<entity>\w+)/(?<id>\w+)/(?<width>[1-9][0-9][0-9]{1}|[1][0-9][0-9][0-9]{1})/(?<file>.+)$" {
# /images/products/id/100/file.jpg >>> Proxy to internal image resizing server
proxy_pass http://127.0.0.1:8888/resize/$entity/$id/$width/$file;
proxy_cache images;
proxy_cache_valid 200 30d;
}
location /assets/ {
alias /var/www/prtzn/theme/assets/;
}
location /sw.js {
root /var/www/prtzn/theme/assets/;
}
location ~ ^/(api|ajax|ws|images)/ {
# Proxy to NodeJS
expires off;
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
try_files $uri @proxy;
}
location @proxy {
# Proxy to NodeJS
expires off;
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
我遵循了 digitalocean 的说明,它们真的很好我已经安装了应用程序但是我的 https 前端出现 502 Bad Gateway 错误。它试图连接并想要握手,但无法做到。给出这样的错误 wsUrl..: wss://188.166.91.39
app-0c847e67113cfb2f2a2f.js:1 WebSocket connection to 'wss://188.166.91.39/ws/dashboard?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZXMiOlsiYWRtaW4iXSwianRpIjoiNWM2YzUyNDNhY2ZmMzgyZGFhZDZiZGNhIiwiZW1haWwiOiJoYW1pdC55aWxkaXJpbS41ODM0QGdtYWlsLmNvbSIsImlhdCI6MTU1MTA0NzI5MiwiZXhwIjoxNTUxMzA2NDkyfQ.AQ96n9cT0Ntab3GqYT-bFbhRlAyZj3tL53K9QjzEonM' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
也许这对你来说会变得非常简单易懂,但我对这类作品不是很有经验,我无法理解这是来自 faint token 还是 nginx 配置,或者是否还有其他错误配置
我的应用程序 运行 pm2 然后我不看 pm2 命令的日志经过一些研究我注意到我的网络 api 不能正常工作,命令无法看到
npm start process.json
因为我的 2 个应用程序正在运行并且在线,但其中一个应用程序没有使用任何内存,所以在注意到我已经尝试
至: npm 开始
我还看到了其他错误。我修好了地雷。真正的错误是后端服务不是运行或没有响应