Reverse Proxy Traffic to Docker Container on CyberPanel

We’ve recently released Docker Manager. If you are running a web application in your Docker Container you may want to reverse proxy traffic from main webserver (OpenLiteSpeed or LiteSpeed Web server Enterprise) to docker container. This setup have few benefits, 2 of them are:

  1. Easily manage SSL from CyberPanel for the domain you are going to setup reverse proxy on.
  2. You can load balance between different containers.
  3. … and more!

You might also be interesed in: HOW TO REMOVE PORT 8090 FROM CYBERPANEL

Step 1: Install CyberPanel and Create Website

You first need to install CyberPanel and create your website. Skip this step if you have already done so. You can also issue SSL for this website.

Step 2: Setup Reverse Proxy

We will see two examples, with OpenLiteSpeed and LiteSpeed Enterprise Web server.

With OpenLiteSpeed

Open command line and edit: /usr/local/lsws/conf/httpd_config.conf

extprocessor dockerbackend {
  type                    proxy
  address                 127.0.0.1:8080
  maxConns                100
  pcKeepAliveTimeout      60
  initTimeout             60
  retryTimeout            0
  respBuffer              0
}

Take note of the address line. Make sure to replace port 8080 with appropriate port (in our case our container was being mapped to port 8080 to the outside world)

Use Rewrite Rules to Proxy traffic to your Container

You can now use rewrite rules to proxy traffic to your container, now edit rewrite rules for the domain you choose in Step 1 using the rewrite rule guide. You can use these rules:

REWRITERULE ^(.*)$ HTTP://dockerbackend/$1 [P]

If you want to force redirect SSL then use the following

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
REWRITERULE ^(.*)$ http://dockerbackend/$1 [P]

With LiteSpeed Enterprise Web server

Let see how we can do the same with LiteSpeed Enterprise Web server. If you have installed CyberPanel Ent, you are using LiteSpeed Enterprise Web server. If you are not already on CyberPanel Ent and want to switch you can read the switch guide.

Open command line and edit: /usr/local/lsws/conf/httpd_config.xml

Paste following content:

<extProcessor>
      <type>proxy</type>
      <name>dockerbackend</name>
      <address>127.0.0.1:8080</address>
      <maxConns>100</maxConns>
      <pcKeepAliveTimeout>60</pcKeepAliveTimeout>
      <initTimeout>60</initTimeout>
      <retryTimeout>0</retryTimeout>
      <respBuffer>0</respBuffer>
</extProcessor>

Make sure to paste it inside in the configuration file. Take note of the address line. Make sure to replace port 8080 with appropriate port (in our case our container was being mapped to port 8080 to the outside world)

Use Rewrite Rules to Proxy traffic to your Container

You can now use rewrite rules to proxy traffic to your container, now edit rewrite rules for the domain you choose in Step 1 using the rewrite rule guide. You can use these rules:

RewriteEngine On
REWRITERULE ^(.*)$ HTTP://dockerbackend/$1 [P]

If you want to force redirect SSL then use the following:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
REWRITERULE ^(.*)$ HTTP://dockerbackend/$1 [P]
3 Likes

i can’t find the entry:

extprocessor dockerbackend {
type proxy
address 127.0.0.1:8080
maxConns 100
pcKeepAliveTimeout 60
initTimeout 60
retryTimeout 0
respBuffer 0
}

in the file: /usr/local/lsws/conf/httpd_config.conf

kann mir dabei jemand helfen?

1 Like

Full Detail tutorial in Hindi i also learn from this channel. #azadeducation Reverse proxy with cyber panel | Server-side rendering (SSR) with Angular Universal - YouTube

U just paste it! :wink:

And why not write in manual this? Paste… Only “edit this” are there…

hi its working but i dont want to expose my container ports.
How can i set a reverse proxy to the internal ip adresses of docker network without exposing ports ?

@morpheus3021 I’m trying to do the same. So the when I go to https://subdomain.domain.com without the port at the end.

The setup described here does not seem to work.

1 Like