How to Use cp.example.com (or Any Subdomain) as a Proxy Frontend for DirectAdmin


How to Use cp.example.com (or Any Subdomain) as a Proxy Frontend for DirectAdmin

By default, DirectAdmin runs on port 2222, meaning you need to access your panel at:

http://server.example.com:2222/

However, some firewalls and networks block custom ports. A better option is to use a subdomain such as cp.example.com and configure it to proxy requests to DirectAdmin. This way, your clients can log in at a clean URL like:

https://cp.example.com

In this guide, we’ll show you how to set up cp.example.com (or any other subdomain) as a frontend proxy for DirectAdmin using Apache, Nginx, or LiteSpeed.


Step 1: Create the Subdomain

  1. Log into DirectAdmin at Admin Level → DNS Administration.
  2. Add a DNS record for cp.example.com pointing to your server IP.
  3. Wait for DNS propagation or update your local hosts file for instant testing.

Step 2: Configure Apache Proxy (if you’re using Apache)

  1. Create a user-level domain cp.example.com under DirectAdmin.
  2. Go to Admin Level → Custom HTTPD Configurations → cp.example.com.
  3. Add the following under the |CUSTOM| section:
ProxyRequests off
SSLProxyEngine on

ProxyPass /phpmyadmin !
ProxyPass /phpMyAdmin !
ProxyPass /webmail !
ProxyPass /roundcube !

ProxyPass / "https://server.example.com:2222/"
ProxyPassReverse / "https://server.example.com:2222/"
  1. Restart Apache:
service httpd restart

Step 3: Configure Nginx Proxy (if you’re using Nginx)

Edit /etc/nginx/nginx-includes.conf and add:

server {
   listen 80;
   server_name cp.example.com;

   location / {
       proxy_pass http://server.example.com:2222/;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}

Then restart Nginx:

service nginx restart

Step 4: Configure LiteSpeed Proxy (if you’re using LiteSpeed)

In Admin → Configuration → Server → External App → Add:

  • Add an external web server pointing to https://cp.example.com:2222.
  • Then, under your virtual host config, add:
RewriteEngine On
RewriteRule ^(.*)$ https://cp.example.com:2222/$1 [P,L]

Restart LiteSpeed after changes.


Step 5: Enable SSL (Recommended)

Since your panel login contains sensitive information, always enable SSL on your cp.example.com subdomain.

  • In DirectAdmin, enable Free SSL via Let’s Encrypt.
  • Once installed, access your panel securely at:
https://cp.example.com

Troubleshooting

  • If you see proxy errors, ensure firewall rules allow port 2222.
  • Check logs in /var/log/httpd/ (Apache), /var/log/nginx/, or LiteSpeed logs.
  • If login fails, verify that the X-Forwarded-For IP setting is enabled in DirectAdmin:
cd /usr/local/directadmin
./directadmin set x_forwarded_from_ip 1
service directadmin restart

✅ That’s it! Now your users can access DirectAdmin at a friendly URL like https://cp.example.com instead of remembering port numbers.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *