Tag: httpd
Wildcard *.domain.com
by admin on Sep.07, 2009, under DirectAdmin
If you’d like to setup your domain to accept anything.domain.com, you can do so with the following guide (Admin access required)
1) Setup the dns with a wildcard A record. Go to Dns Control, and add an "A" record:
* -> 1.2.3.4
where 1.2.3.4 is the IP of your domain.
This will allow anything.domain.com to resolve to your server. Apache does not yet know how to direct that name though.
2) To setup apache, go to:
Admin Level -> Custom Httpd configurations -> domain.com
In the top text area, add this *one* line:
ServerAlias *.|DOMAIN|
then click "Save".
That should be it. Wait a few minutes for everything (apache, named) to be restarted then test it out.
The wildcard subdomains will point to your main public_html directory for the domain.
If you want to change this, it’s probably best not to do step 2, and to setup your own custom virtualhost manually into the /etc/httpd/conf/httpd.conf (DA wont delete/overwrite it there) with the same ServerAlias directive as in step 2.
Other similar uses might be subdomain aliasing, where test.domain.com is the same as test.domain2.com.
You can accomplish this by following step 1) above, then insert the following instead of step 2) above:
|*if SUB|
ServerAlias |SUB|.domain2.com
|*endif|
which will make any existing subdomain from domain2.com point to domain.com.
How to add all of the Include lines into your httpd.conf
by admin on Sep.07, 2009, under DirectAdmin
If you reinstall DA (./directadmin i) on a live box, your /etc/httpd/conf/httpd.conf file will get overwritten and emptied of all data. You’ll need to read all of the Include lines for your users so that their sites show up (you’ll be seeing the apache pages, or the shared IP pages instead)
Type:
cd /usr/local/directadmin/data/users
for i in `ls`; do { echo "Include /usr/local/directadmin/data/users/$i/httpd.conf" >> /etc/httpd/conf/httpd.conf; }; done;
Note that this add the include lines for *all* users.. so if you’ve added users to DA after you ran the "./directadmin i", you’ll end up with duplicates. Make sure you don’t have duplicate Include lines.. (apache won’t restart, it will let you know)
How to downgrade from apache 2 back to apache 1.3
by admin on Sep.07, 2009, under DirectAdmin
If you need to go back to apache 1.3 after installing apache 2, you’ll need to do the following:
1) Restore the old httpd.conf file:
cp -f /etc/httpd/conf/httpd.conf.1.3.backup /etc/httpd/conf/httpd.conf
2) Get DirectAdmin to use the old httpd.conf files for the users. Edit the /usr/local/directadmin/conf/directadmin.conf file and change apache_ver=2.0 to apache_ver=1.3. Also, if you were using custombuild, and are going back to customapache, the apache_conf value needs to be reset to:
apacheconf=/etc/httpd/conf/httpd.conf
Then type
echo "action=rewrite&value=ips" >> /usr/local/directadmin/data/task.queue
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
echo "action=directadmin&value=restart" >> /usr/local/directadmin/data/task.queue
3) Now you can recompile apache 1.3
rm -f /usr/lib/apache/*
cd /usr/local/directadmin/customapache
./build clean
./build all
4) Fix the modules link:
cd /etc/httpd
rm -f modules
ln -s /usr/lib/apache modules
5) Restore the old boot script:
FreeBSD:
cp -f /usr/local/directadmin/customapache/httpd_freebsd /usr/local/etc/rc.d/httpd
chmod 755 /usr/local/etc/rc.d/httpd
/usr/local/etc/rc.d/httpd restart
RedHat:
cp -f /usr/local/directadmin/customapache/httpd /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
/etc/init.d/httpd restart
![]()
Apache won’t restart: [crit] (98)Address already in use: make_sock: could not bind to port 8090
by admin on Sep.07, 2009, under DirectAdmin
Note this is an old guide. It was for apache 1.3 with customapache. The current boot script we provide shouldn’t have this issue.
If apache is not completely shutting down, consider trying graceful restarts (see related link below) and also ensure your system is updated such that you don’t have any outdated php scripts on the server.
[crit] (98)Address already in use: make_sock: could not bind to port 8090
or
[crit] (98)Address already in use: make_sock: could not bind to port 443
or
[crit] (98)Address already in use: make_sock: could not bind to port 80
If you see this error in your /var/log/httpd/error_log, it would mean that apache isn’t shutting down completely before trying to restart. This means that the new process won’t be able to bind to the given ports because they’re still being used by the old copy of apache that wasn’t completely shut down.
To solve this, use a different boot script that will wait for all apache processes to stop before starting the new one:
cd /usr/local/directadmin/customapache
rm -f httpd*
./build update
Once you have the new scripts downloaded, you need to install them:
RedHat:
cp httpd /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
chkconfig httpd reset
FreeBSD:
cp httpd_freebsd /usr/local/etc/rc.d/httpd
chmod 755 /usr/local/etc/rc.d/httpd
Using a custom VirtualHost template
by admin on Sep.07, 2009, under DirectAdmin
If you wish to change the setup of the VirtualHosts for all domains, you can do so by creating your own custom templates.
cd /usr/local/directadmin/data/templates
cp virtual_host*.conf custom
cd custom
Once you’ve copied the 4 VirtualHost files (or just the ones you want) to the custom directory, you can then edit the new files you’ve just copied. DirectAdmin will always check for the custom file before going to the default ones. Failure to copy the virtual_host*.conf files to the custom directory before modifying them will result in a loss of all changes when DirectAdmin updates itself (the files are overwritten). Note that there are actually 8 virtual_host files, but you only need to worry about the 4 that apply to you. The files with the 2 in them are for apache 2.x. The ones without the 2 in them are for apache 1.3.
Inside the virtual_host*.conf files, you’ll find code that is similar to httpd.conf code, but contains what are known as tokens. These tokens are what will be replaces with specific user data for each domain created.
Available tokens
DOMAIN
the name of the domain. eg: domain.com
IP
the IP address associated with that domain. eg: 192.168.3.4
HOME
The users home directory. eg: /home/gary
ADMIN
The email address of the server admin. webmaster@domain.com
HOSTNAME
The hostname of the server. eg: server.domain.com
SAFE_MODE
ON or OFF if php safe_mode is enabled or not
PHP
ON or OFF if php is enabled or not
CGI
The whole httpd.conf line used to add the Script-Alias
HANDLERS
httpd.conf code holding all apache handlers
MIMETYPE
httpd.conf code holding all apache mime types
USER
the username
GROUP
the users group name (99% of the time, it’s the same as the USER)
DOCROOT
The DocumentRoot of the VirtualHost. This is the path that apache will use to access the data when the ServerName (domain.com) is requested
SUB
for the virtual_host_*sub.conf file, the subdomain name. eg: sub
CUSTOM
custom httpd.conf code to be inserted if the domain.com.cust_httpd file exists. (See Adding custom httpd.conf code the VirtualHost of one domain)
CAROOT
The whole httpd.conf line used to load in the SSLCACertificateFile directive
CERT
The path of the certificate to be used for the domain
KEY
The path of the certificate to be used for the domain
The top of the templates should contain |?CGI=…| and |?DOCROOT=…|. These lines are where the data for the CGI and DOCROOT tokens are set. If cgi is not enabled, this line wil be ignored and the CGI token will be empty. If the domain is suspended, the DOCROOT will be filled the the path of the suspend page. The CAROOT token will be empty unless the User has added a valid CARootCertificate through DA.
You can use tokens when assigning a value to CGI or DOCROOT, just use `TOKEN` instead of |TOKEN|.
Once you are happy with your new virtual_host*.conf files they’ll need to be used in the real httpd.conf files. You can trigger DirectAdmin to rewrite all User httpd.conf files by running:
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
The command will be added the the task queue which is checked once per minute, so it may be a few minutes before all httpd.conf files have been rewritten. *Note: the main /etc/httpd/conf/httpd.conf is never overwritten (unless DirectAdmin is reinstalled) so any changes you make will be safe.
Note, that you can also use if-then-else statements if you don’t want all settings to be global. Example, say you want a custom item added, only for 1 domain:
|*if DOMAIN="domain.com"|
#custom item for just this domain
|*endif|
See the if-then-else link for more info on what else you can do with this basic scripting tool.
You can also run actual scripts with database queries, etc… if you wanted using the script portion of the templates.
More info on that here: http://www.directadmin.com/features.php?id=756
