Add a Virtual Host to Apache

From Zanecorpwiki

Jump to: navigation, search

In the standard configuration, each domain is bound to an IP based virtual host.

  1. goto the configuration directory, 'cd `yquery -W home apache`/conf/services/' in the standard config
  2. create the host configuration file for the domain, the standard name is the domain name followed by '.conf'; e.g., 'exampledomain.com.conf'
  3. create or install the host SSL certs if necessary (TODO: link)
  4. restart apache (see below)
  5. add some content and make sure you can reach the new site via your web browser (TODO: I believe that, if the domain is new, the DNS info will not be cached so propagation issues should not normally be a factor here)

Basic domain configuration file:

<VirtualHost 192.168.0.1:42069> # change to your IP
        ServerAdmin webmaster@exampledomain.com #change exampledomain.com to your domain
        DocumentRoot /home/acmeweb/sites/exampledomain.com/www
        ServerName www.exampledomain.com
        ErrorLog logs/exampledomain.com-error_log
        CustomLog logs/exampledomain.com-access_log combined
</VirtualHost>
<VirtualHost 192.168.0.1:42070>
        ServerAdmin webmaster@exampledomain.com
        DocumentRoot /home/liquidweb/sites/exampledomain.com/www
        ServerName www.exampledomain.com
        ErrorLog logs/secure.exampledomain.com-error_log
        CustomLog logs/secure.example.com-access_log combined
        SSLEngine on
        SSLCipherSuite SSLv2:SSLv3:TLSv1:+HIGH:+MEDIUM
        SSLCertificateFile /home/acmeweb/build/ymake/modules/apache/ssl/certs/apachecert.pem
        SSLCertificateKeyFile /home/acmeweb/build/ymake/modules/apache/ssl/private/apachekey.pem
</VirtualHost>

You can restart apache most easily by running 'ymake -a stop apache; ymake -a start apache'. You can also get apache to reload the configuration file without actually shutting down with (assuming a standard apache-ymake install):

cd `yquery -W home apache`
cat ~/build/yusers/yapache_acmeweb/yapache_acmeweb_password | sudo -S -u yapache_acmeweb ./bin/apachectl -k restart -f conf/yapache-httpd.conf'

Where 'acmeweb' is replaced with the ymake service sub-user name. Note that in either case, if you have errors in your config files, apache will fail to start up, so double check when seconds of downtime actually count. (TODO: provide command to check config syntax)

If the content does not come up, make sure that apache restarted without any errors. If there are any other sites hosted, make sure you can still get to them. Use the 'host' command (or similar) to check that the DNS information is set up properly.

Personal tools