Wednesday, May 22, 2013

Apache Server Configuration with Name Based Hosting in RedHat Linux 6

My Configuration,

Operating System  :  redhat 6.3 32bit server
Hostname          :  redhatserver.sourav.com
IP Address        :  192.168.0.101
Client Details:

Operating System  :  redhat 6.3 32bit Desktop
Hostname          :  client.sourav.com
IP Address        :  192.168.0.10


Prerequisites:

1. Set the hostname of redhatserver server

[root@redhatserver ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=redhatserver.sourav.com
2. Add the redhatserverserver hostname in ‘etc/hosts’ file

[root@redhatserver ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250   redhatserver.sourav.com
192.168.1.250   www.sourav.com
3. Install Apache

Check and remove any previously installed packages
[root@redhatserver ~]# rpm -qa | grep httpd
or
[root@redhatserver ~]# yum list installed | grep httpd
Now install the ‘httpd’ package
[root@redhatserver ~]# yum install httpd* -y
4. Configure Apache

[root@redhatserver ~]# vi /etc/httpd/conf/httpd.conf
## line no 262 - Set the server admin mail id which is used to receive mail generated by apache ##
ServerAdmin root@sourav.com
## line no 276 - Set the redhatserversite name ##
ServerName www.sourav.com:80
## line no 292 - Set the redhatserver pages folder ##
DocumentRoot "/var/www/html"
## line no 402 - Sent the index or home page of the redhatserversite ##
DirectoryIndex sourav.html
5. Create a sample index or home page

Create the index or home page html file in the ‘/var/www/html/’ directory
[root@redhatserver ~]# vi /var/www/html/sourav.html


 Welcome to sourav redhatserversite 

6. Allow redhatserverserver through firewall

[root@redhatserver ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Restart iptables to save changes
[root@redhatserver ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
7. Start Apache redhatserver server

[root@redhatserver ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@redhatserver ~]# chkconfig httpd on
Client side Configuration

1. Add the redhatserverserver and client ip address and hostname in the ‘/etc/hosts’ file

[root@client ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.251   client.sourav.com
192.168.1.250   www.sourav.com
 for name based hosting

VirtualHost *:80
    # This first-listed virtual host is also the default for *:80
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /www/domain
/VirtualHost

VirtualHost *:80
    ServerName other.example.com
    DocumentRoot /www/otherdomain
/VirtualHost

You can alternatively specify an explicit IP address in place of the * in VirtualHost directives. For example, you might want to do this in order to run some name-based virtual hosts on one IP address, and either IP-based, or another set of name-based virtual hosts on another address.

Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive, placed inside the VirtualHost section. For example in the first VirtualHost block above, the ServerAlias directive indicates that the listed names are other names which people can use to see that same redhatserver site:

ServerAlias example.com *.example.com

use name based hosting

uncomment the next line

NameVirtualHost *:80


install elinks browser

rpm -ivh elinks*

then from terminal

elinks www.sourav.com
elinks www.test.com

No comments:

Post a Comment