Top community members

In the past we had a dream,
to have place where we could share IT knowledge,
to ask questions without fear that someone will judge us.

Now we are a group of people who make this dream come true. ❤ 💻

If you think sharing knowledge and helping other is valuable.

join our community - Click here


apache2 - redirect http:// and ws:// with proxy module

8 points
Created by:

In this article we are going to look on problem how to redirect domain traffic that uses both websockets and http from one address to another with apache2. In network we can find a lot of examples that do not work because of redirection rules priority. This example was tested on Debian but can be used with other operating systems too.

To solve the problem it is necessary to execute following steps:

1. Enable proxy modules

To make redirection possible it is necessary to enable proxy modules at first.

Note: this approach was tested with apache 2.4.

Execute in terminal following commands to enable apache2 modules: 

a2enmod rewrite
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_wstunnel

2. Create ViarutaServer configuration

Create new or open one of the files located in /etc/apache2/sites-enabled/ directory and put following rule inside:

<VirtualHost *:80>

  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /(.*)           http://localhost:8080/$1 [P,L]

  ProxyPassReverse / http://localhost:8080/

Note: this configuration redirects all trafic from address (port 80) to localhost:8080 address including ws:// and http://.

3. Restart apache2 server

Run followin command to restart apache2 serwer:

systemctl restart apache2

Note: replace command with other if non Debian operating system is used.

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more