Thursday 13 October 2011

Basic web server configuration in RHEL / CENTOS


Packages required – httpd
                               httpd-devel
                               httpd-manual
Daemon - /usr/sbin/httpd
Script -     /etc/init.d/httpd
Ports -       80/tcp (http) , 443/tcp (https)
Configuration - /etc/httpd/*
                          /var/www/*

These are the things to be thought of while setting web server.
Step 1: Install the web server packages using yum
# yum install httpd*

Step 2: Edit the configuration file which is "/etc/httpd/conf/httpd.conf"
# vim /etc/httpd/conf/httpd.conf 

> find the line containing this one (around line nu 270)
#ServerName www.example.com:80
and make it as 
ServerName server.example.com:80

Here server.example.com is the hostname of my server
> next, find the line containing ( around lin nu 990)
#NameVirtualHost *:80

and make it as  below
NameVirtualHost 172.16.0.1:80
Here 172.16.0.1 is the ip of my server.

> now edit the last 7 lines
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

as

<VirtualHost 172.16.0.1:80>
    ServerAdmin root@server.example.com
    DocumentRoot /var/www/html
    ServerName server.example.com
    ErrorLog logs/server.example.com-error_log
    CustomLog logs/server.example.com-access_log common
</VirtualHost>

> of the above mentioned configuration
    "DocumentRoot /var/www/html" is the location of our index.html page.
    "ServerName server.example.com" is the name which is used to browse/access the content in the "/var/www/html" directory.

Thats all about editing the configuration file. Now save and quit the editor.

Step 3: Now create the contents in the default web server's home directory (index.html)
# vim /var/www/html/index.html
===============================
<html>
<head><title>Home Page</title></head>
<body>
<font size="10">
<b>Welcome to server.example.com</b>
</font></body></html>
===============================

Now exit the editor.

Step 4: Now check the Selinux context of index.html
The newly created index.html file will not have the selinux context required for web server. So add the policy

# chcon -R --reference=/var/www/html/ /var/www/html/index.html

Check whether it has the right context

# ls -lZ /var/www/html/index.html
-rw-r--r--. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
Now its ok.

Step 5: Start the daemon

# service httpd start
#chkconfig httpd on 

Step 6: Browse the contents





No comments:

Post a Comment

Navigation by WebRing.