Дубликат для WebSockets и Apache-прокси: как настроить mod_proxy_wstunnel?
Я следовал инструкциям этого ответа: https://stackoverflow.com/a/35141086/4763630
Это окончательная конфигурация Apache2для моего сервера:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName service.example.com
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) wss://service.example.com/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) https://service.example.com/$1 [P,L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName service.example.com
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:1886/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:1996/$1 [P,L]
ProxyPassReverse / https://service.example.com
<Location "/">
Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
</Location>
SSLEngine On
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCipherSuite HIGH:MEDIUM
SSLCertificateFile cert.pem
SSLCertificateKeyFile privkey.pem
SSLCertificateChainFile chain.pem
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Теперь я могу получить доступ с http://
, https://
, ws://
и wss://
.