Wednesday, March 19, 2008

Running DirectAdmin through apache on port 80

Several people are unable to connect to DirectAdmin on port 2222 due to firewalls or proxies. It is possible to setup apache to allow DirectAdmin to run through apache using it's proxy options.

In this example, we'll setup DirectAdmin to run through cp.domain.com for any domain on your machine. This can be tweaked however you wish.

1) Duplicate the VirtualHost template:

cd /usr/local/directadmin/data/templates
cp virtual_host.conf custom
cd custom

You can copy all of the virtual_host*.conf files if you wish to access it with any method (https etc).

2) Make the changes to the template. Edit the newly copied virtual_host.conf files (repeat this for the other VirtualHost files if you copied them). Add


ServerName cp.|DOMAIN|
ProxyRequests Off
ProxyPass / http://localhost:2222/
ProxyPassReverse / http://localhost:2222/


To the end of the virtual_host.conf file, just after the virtualhost that is already there. (Yes, there will be 2 in one file). Repeat this for the other files if you copied them (but use 443 for the ssl version, with the ssl related options). If this is apache 2, you may need to add "SSLProxyEngine on" into the virtualhost if you are using DA with SSL.

3) Enable mod_proxy in your /etc/httpd/conf/httpd.conf file. Edit that file and uncomment the followig lines (remove the # character)

LoadModule proxy_module modules/libproxy.so

AddModule mod_proxy.c


4) rewrite the user httpd.conf files:

echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue


Wait a few minutes for the rewrite to happen and for apache to restart itself.

5) You'll also need to add a cp A record for all your domains so that cp.domain.com actually resolves. To get DA to add one by default for new zones:

cd /usr/local/directadmin/data/templates
cp dns_a.conf custom
cd custom
echo "cp=|IP|" >> dns_a.conf


6) Note that the Proxy requets will use a "Host" apache header value of "localhost", which causes the webmail, squirrelmail and phpMyAdmin links to be (eg): http://localhost/webmail. You can change that by adding:

|?HOSTNAME=yourhost.com|

at the very top of /usr/local/directadmin/data/skins/enhanced/header.html so that it overwrite the previous setting of "localhost". Another method would be to use "ProxyPass / http://yourhost.com:2222/" instead of "ProxyPass / http://localhost:2222/".

No comments: