我正在嘗試使我的網站與 nodejs 后端和 websocket 服務器一起使用
我的網站完全在 https 我的節點后端在埠 8080 上,我的 websocket 服務器在 8080 我做了一個這樣的虛擬主機
<VirtualHost *:8080>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:8080/$1 [P,L]
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/example.com
ServerName www.example.com
ServerAlias example.com
<Directory /var/www/example.com>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Allow from all
Require all granted
</Directory>
<Directory /var/www/example.com/wp-content>
Options -Indexes FollowSymLinks MultiViews
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15553000; includeSubDomains; preload"
</IfModule>
ErrorLog /var/log/apache2/error.example.com.log
CustomLog /var/log/apache2/access.example.com.log combined
</VirtualHost>
但是,當我嘗試使用 myip:8080 時,它無法正常作業,并且無法連接到我的 websocket 我做錯了什么?
uj5u.com熱心網友回復:
使能夠 mod_proxy_wstunnel
然后您應該只能將您的位置轉發到您的 websocket 服務器。
ProxyPass /wssurl/ ws://127.0.0.1:8080/
uj5u.com熱心網友回復:
好的,經過大量作業。我想通了。我認為問題出在我安裝網站時的防火墻上。
所以我必須通過我的安全連接代理傳遞所有內容。這mod_proxy_wstunnel不起作用,因為當我嘗試與 wss:// 連接時,我不得不使用 rewriteEngine。
這是我最后的作業虛擬主機
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/example.com
ServerName www.example.com
ServerAlias example.com
<Directory /var/www/example.com>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Allow from all
Require all granted
</Directory>
<Directory /var/www/example.com/wp-content>
Options -Indexes FollowSymLinks MultiViews
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15553000; includeSubDomains; preload"
</IfModule>
ErrorLog /var/log/apache2/error.example.com.log
CustomLog /var/log/apache2/access.example.com.log combined
ProxyRequests On
ProxyPreserveHost On
ProxyPass /api/test http://localhost:8080
ProxyPassReverse /api/test http://localhost:8080
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://localhost:8080/$1" [P,L]
</VirtualHost>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/322350.html
