Pages

Saturday, October 18, 2014

Apache virtual host

My company asks me to create two new websites. One for the internal intranet another one for the internal blog. For the intranet drupal should be used and for the blog wordpress should be used. To sum it up: two new websites accessable under:

http://intranet.company.com
http://blog.company.com

I deceided to put both websites onto our internal webserver www01.company.com running Slackware as usual.
The first thing I did was to create two new directories where the software for drupal and wordpress will be installed:

# mkdir /var/www/drupal
# mkdir /var/www/wordpress


Then I created a virtual host config file for apache:

# vi /etc/httpd/vhost.config
<VirtualHost *:80>
  ServerName intranet.company.com
  ServerAlias intranet
  DocumentRoot /var/www/drupal
  <Directory "/var/www/drupal">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName blog.company.com
  ServerAlias blog
  DocumentRoot /var/www/wordpress
  <Directory "/var/www/wordpress">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
  </Directory>
</VirtualHost>


Both entries are more or less equal. They just listen on all available IP's on port 80, have a different server name and so on. The important different for both entries are ServerName and DocumentRoot. Where /var/www/wordpress will hold all wordpress files for the blog and /var/www/drupal will hold all drupal files for the company's brand new intranet page.
The above configuration file vhost.conf must be included into the apache configuration file httpd.conf:

# vi /etc/httpd/httpd.conf
...
# Virtual Hosts
Include /etc/httpd/vhost.conf


Now apache must be restarted:

# /etc/rc.d/rc.httpd restart

If somebody calls blog.company.com now the content under /var/www/wordpress would be loaded - would! The last step is to modify the forward zone inside the DNS confoiguration. First freeze the zone (in case that rndc is not configured edit the zone file and restart named):

# rndc freeze company.com

Then add two entries intranet and blog with the same IP address for www01 (the origin web server):

# vi /var/named/zones/company.com
...
www01                   A       192.168.1.45
intranet                A       192.168.1.45
blog                    A       192.168.1.45
...


Next thaw the zone again:

# rndc thaw company.com

Finally the addresses intranet.company.com and blog.company.com are available and both pages are accessable.

No comments:

Post a Comment