最近小程序用到WebSockets,服务器安装完环境和配置完nginx配置后老是出现错误代码1006;百思不得其姐之后,怀疑是因为自己nginx转发配置错了
最后发现,wss配置需要配置在ssl配置下,而我写错地方了,下面列出正确的配置
location /wss/
{
proxy_pass http://127.0.0.1:2345;
proxy_set_header X-Real-IP remote_addr;
proxy_set_header Hosthost;
proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgradehttp_upgrade;
proxy_set_header Connection "upgrade";
rewrite /wss/(.*) /$1 break;
proxy_redirect off;
}
服务器nginx完整配置
server {
listen 80;
root /www/web/app_xxx_com/public_html;
server_name app.xxx.com;
index index.php;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 503 /errpage/503.html;
location ~ \.php{
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location ~ /\.ht {
deny all;
}
location / {
try_filesuri @apache;
}
location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
}
server {
listen 443;
root /www/web/app_xxx_com/public_html;
ssl on;
ssl_certificate cert/app.xxx.com.pem;
ssl_certificate_key cert/app.xxx.com.key;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
server_name app.xxx.com;
index index.php;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 503 /errpage/503.html;
location ~ \.php{
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location ~ /\.ht {
deny all;
}
location / {
try_filesuri @apache;
}
location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location /wss {
proxy_pass http://127.0.0.1:2345;
proxy_http_version 1.1;
proxy_set_header Upgrade http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IPremote_addr;
}
}
参考链接:https://wenda.workerman.net/question/1485
https://blog.csdn.net/Phoenix_smf/article/details/89278398