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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值