nodebb下Apache配置ssl导致websocket/wss失效出现400错误的解决方案

请确保apache 最低版本2.4以上
参考官方proxy文档 配置443端口
Configuring Apache as a proxy

<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com

# Rewrite any http traffic to the main url https site
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^[^\/]*\/(.*) https://www.example.com/$1 [R=301,L]
</IfModule>
</VirtualHost>

<VirtualHost *:443>
Protocols h2 http/1.1
ServerName www.example.com

# your SSL证书
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/privkey.pem
SSLCertificateChainFile /path/to/chain.pem

# Basic security headers
Header always set X-Content-Type-Options "nosniff"
Header always set X-Xss-Protection "1; mode=block"

# NodeBB header
RequestHeader set X-Forwarded-Proto "https"

# Static file cache
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css)$">
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 14 days"
Header set Cache-Control "public"
</IfModule>
</FilesMatch>

ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

# Custom Error Document when NodeBB is offline
ProxyPass /error-documents !
ErrorDocument 503 /error-documents/503.html
Alias /error-documents /path/to/nodebb/public

# Websocket passthrough 4567是你当前的端口
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:4567/$1 [P,L]

ProxyPass / http://localhost:4567/
ProxyPassReverse / http://localhost:4567/

# Log stuff
ErrorLog ${APACHE_LOG_DIR}/www-example-error.log
CustomLog ${APACHE_LOG_DIR}/www-example-access.log combined
</VirtualHost>

不修改socket的配置 到这一步应该就可以了
如果遇到session-ID失效的问题 ,看看是不是nodebb config.json域名是否正确,socketio配置是否正确
https://community.nodebb.org/topic/4383/hundreds-of-polling-requests/34

{
"url": "https://your domain",
"secret": "e79feff0-b6b6-4d36-8389-c7fdbc52f171",
"database": "mongo",
"mongo": {
"host": "yourt host",
"port": "your database prot",
"username": "your name",
"password": "your pass",
"database": "your database",
"uri": ""
},
"socket.io": {
"transports": ["websocket"]
}
}

改完之后如果无效尝试下重启服务和nodebb

所写所说,是心之所感,思之所悟,行之所得;文当无敷衍,落笔求简洁。 以所舍,求所获;有所依,方所成!

更多请关注:老梁`s Blog

免责声明,若由于商用引起版权纠纷,一切责任均由使用者承担。 您必须遵守我们的协议,如果您下载了该资源行为将被视为对《免责声明》全部内容的认可->联系老梁投诉资源
Laoliang.Net资源全部来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。 敬请谅解! 侵权删帖/违法举报/投稿等事物联系邮箱:service@laoliang.net
老梁`s Blog(老梁博客) » nodebb下Apache配置ssl导致websocket/wss失效出现400错误的解决方案

发表评论

本站承接,网站推广(SEM,SEO),软件的安装的安装与调试,服务器的推荐以及配置,APP的开发与维护,网络或者web维护;财务软件,客户管理系统,人力资源,超市POS,医药管理,服务器安全,ecshop,金蝶,用友,管家婆;

立即查看 了解详情