DELIVERABLE
Web server with two virtual hosts.
INSTALLATION
[root@server ~]# yum install httpd httpd-manual mod_ssl
[root@server ~]# chkconfig httpd on
IPTABLES
[root@server ~]# iptables -I MYCHAIN -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
[root@server ~]# iptables -I MYCHAIN -s 192.168.1.0/24 -p udp --dport 80 -j ACCEPT
[root@server ~]# service iptables save
Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
CONFIGURATION
Take advantage of the manual:
[piotr@server ~]$ firefox /var/www/manual/index.html
The main configuration file /etc/httpd/conf/httpd.conf should have the following lines. No need to tamper with the rest for now.
At the bottom of the file you should have something similar:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.example.com
</VirtualHost>
Create a sample index.html:
[root@server ~]# echo "www.example.com" > /var/www/html/index.html
The rule to resolve www.example.com has to be added into the zone file. We just point www into server:
[root@server ~]# cat /var/named/example.com.zone
$TTL 86400
@ IN SOA server.example.com. root.example.com. (
45 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
NS server
server A 192.168.1.1
piotr A 192.168.1.2
www CNAME server
Restart named:
[root@server ~]# service named restart
Stopping named: [ OK ]
Starting named: [ OK ]
Now it can be tested with firefox or directly in CLI with elinks or lynx.
SECOND VIRTUAL HOST
Let's add one more virtual host into our configuration. To make the things more complicated we will place the Document Root in /virtual.
Modify the /etc/httpd/conf/httpd.conf by adding the following lines:
<VirtualHost *:80>
DocumentRoot /virtual
ServerName www2.example.com
</VirtualHost>
Again add the right pointer into zone file and restart named:
[root@server ~]# echo "www2 CNAME server" >> /var/named/example.com.zone
[root@server ~]# service named restart
Stopping named: [ OK ]
Starting named: [ OK ]
Create the root directory and add index.html
[root@server ~]# mkdir /virtual
[root@server ~]# echo "www2.example.com" > /virtual/index.html
Now we need to set the proper SELINUX context on this directory. It should be the same as the one set on /var/www:
[root@server ~]# semanage fcontext -l |grep /var/www
[root@server ~]# semanage fcontext -a -t httpd_sys_content_t "/virtual(/.*)?"
[root@server ~]# restorecon -Rv /virtual/
restorecon reset /virtual context user_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /virtual/index.html context user_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
VERIFICATION
Now both addresses www.example.com and www2.example.com should give different home pages served from different locations.
No comments:
Post a Comment