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:
- Easily manage SSL from CyberPanel for the domain you are going to setup reverse proxy on.
- You can load balance between different containers.
- … 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]