nginx配置:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /path/to/tls/tls.crt;
ssl_certificate_key /path/to/tls/tls.key;
server_name the.domain.tld;
location / {
proxy_pass http://localhost:5001;
}
location /api/socket {
proxy_pass http://localhost:5001/api/socket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}
阿帕奇配置:
<VirtualHost *:443>
ServerName the.domain.tld
ProxyPass / http://localhost:5001/
ProxyPassReverse / http://localhost:5001/
ProxyPass /api/socket http://localhost:5001/api/socket/
ProxyPassReverse /api/socket http://localhost:5001/api/socket/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /(.*) "ws://localhost:5001/$1" [P,L]
ProxyPreserveHost On
ProxyAddHeaders On
RequestHeader set X-Forwarded-Proto "https"
SSLCertificateFile /path/to/tls/tls.crt
SSLCertificateKeyFile /path/to/tls/tls.key
SSLProxyEngine On
</VirtualHost>
答案1
解决了!我所要做的就是使用 启用 websocket 模块sudo a2enmod proxy_wstunnel
。