Monday, July 29, 2013

Creating Apache2 Virtualhost via Webmin

Here are some useful steps on creating Apache Virtualhost via Webmin... so that you don't have to create them via editing directly the apache2.conf / httpd.conf. Thanks to http://rimuhosting.com.
  • Go to your Webmin control panel.
  • Upgrade to the latest version of webmin (required if you are running a version older than 1.080, and normally advisable regardless).
  • Go to servers.
  • Go to Apache WebServer.
  • In the 'Create a New Virtual Server' section select "Any Address" (so you do not end up with a hard coded IP addresses in your conf file)
  • Enter 80 for Port (and select the last radio button).  This way the VirtualHost will co-exist with any SSL-enabled virtual hosts you add later on.  SSL-enabled VirtualHosts need to listen on port 443.
  • In the "Document Root" field enter where the virtual host HTML files will be.  For example, /home/vhostdomain.com/htdocs.
  • For "Server Name" enter the domain name for which you want to serve pages.  e.g. "vhostdomain.com"
After you have created the Virtual Host, there are a few other things you may wish to edit.
For example, click on the Virtual Host, and go to Networking and Addresses.  Enter an "Alternate virtual server names" of *.YourOtherDomain.com.  With this setting, your virtual host will serve pages for http://yourotherdomain.com/ as well as http://www.yourotherdomain.com/.
At this point you may also wish to set other options like "Log Files", so the log files for the Virtual Host end up in separate log file from the main server's log files.
To activate your changes, click "Apply Changes" on the main Apache Webmin page.
Of course, be sure to configure your DNS server so the virtual host domain name points to your server's IP address.
Webmin creates a VirtualHost directive in the Apache config file (/etc/httpd/conf/httpd.conf).  An example VirtualHost directive looks like this:


DocumentRoot /home/vhostdomain.com/htdocs
ServerName vhostdomain.com
ServerAlias *.vhostdomain.com

See http://httpd.apache.org/docs/2.2/vhosts/examples.html for some more VirtualHost examples.

No comments: