How to proxy wss to ws with .htaccess?

Member

by dedrick , in category: Third Party Scripts , 3 months ago

How to proxy wss to ws with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by orpha , 3 months ago

@dedrick 

To proxy WebSocket Secure (wss) connections to WebSocket (ws) using .htaccess, you can use the following rules:

  1. Enable the required modules in Apache by adding the following lines to your Apache configuration file:
1
2
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so


  1. Create or edit the .htaccess file in your web root directory and add the following rules to proxy wss to ws:
1
2
3
4
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule ^(.*)$ ws://<your_target_server>/$1 [P,L]


Replace "<your_target_server>" with the actual target WebSocket server address.

  1. Save the .htaccess file and restart Apache for the changes to take effect.


With these rules in place, incoming wss requests will be proxied to ws, allowing your WebSocket server to handle secure connections.