截至 2 天前,nginx 开始支持 websocket 连接,因此我试图让我的 nginx-nodejs-socket.io 应用程序在没有 HAproxy 等的情况下工作(虽然运气不好)。
我真正想要实现的是 nginx 仅将 websocket 连接请求发送到支持的服务器,或者更准确地说是 websocket 服务器,socket.io,同时 nginx 将提供 php 文件,以及包括 html 文件在内的所有静态内容.我根本不想 express 提供静态内容(如果可能的话)。
这是我的 nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip …Run Code Online (Sandbox Code Playgroud)