Wednesday, 20 April 2011

how to configure HTTP or WebServer


HTTPD service
daemon:                 httpd
package:                httpd, httpd-devel, httpd-manual
scripts:
ports:                                   
conf file:q             /etc/httpd/conf/httpd.conf
server data:            /var/www/*

Installing httpd service
1.install the package                                  #yum install httpd* -y
2.Hangup the service in service tray                   #chkconfig httpd on
3.Start the service                             #service httpd start
4.Test your system that whether httpd                  #netstat -ntulp | grep ":80"
        service have installed or not           #links http://localhost

Configure default web site at your server
1 Check your hostname                                  #dig -x 192.168.9.117                                  [ur ip]
2 Declare default site(non-virtual)                    #vim /etc/httpd/conf/httpd.conf
                                                ServerName station17.example.com:80             [uncomment it]
OR
2 Declare default site(single virtualhost)             #vim /etc/httpd/conf/httpd.conf
                                                #ServerName station17.example.com:80     [commnent it]

NameVirtualHost *:80                     [declare this section]
                                                                     <VirtualHost *:80>
                                                                     ServerAdmin root@station15.example.com
                                                                     DocumentRoot /var/www/html/
                                                                     ServerName station15.example.com
                                                                     </VirtualHost>
3.create default page for your site                           #vim /var/www/html/index.html
4.restart the service                                         #service httpd restart

Configuring Virtual Hosting
Type of Virtual Hosting
      Default hosting(nonvirtual)
      name based virtual hosting(single/multiple)
      ip based virtual hosting
      port based virtual hosting

Configure default site(non-virtual)                   #vim /etc/httpd/conf/httpd.conf
                                                            ServerName station17.example.com:80            [uncomment it]
Configure name based virtual hosting(single)          #vim /etc/httpd/conf/httpd.conf
      (can be used as default site)                         NameVirtualHost *:80
                                                             <VirtualHost *:80>
                                                             ServerAdmin webmaster@server1.example.com
                                                             DocumentRoot /var/www/html
                                                             ServerName server1.example.com
                                                             #    ErrorLog logs/dummy-host.example.com-error_log
                                                             #    CustomLog logs/dummy-host.example.com-access_log common
                                                             </VirtualHost>
Configure Name based Virtual Hosting(multiple)        #vim /etc/httpd/conf/httpd.conf
                                                             NameVirtualHost *:80
                                                             <VirtualHost *:80>
                                                             ServerAdmin webmaster@server1.example.com
                                                             DocumentRoot /var/www/html
                                                             ServerName server1.example.com
                                                             #    ErrorLog logs/dummy-host.example.com-error_log
                                                             #    CustomLog logs/dummy-host.example.com-access_log common
                                                             </VirtualHost>

                                                             <VirtualHost *:80>
                                                             ServerAdmin webmaster@www.example.com
                                                             DocumentRoot /var/www/www
                                                             ServerName www.example.com
                                                             #    ErrorLog logs/dummy-host.example.com-error_log
                                                             #    CustomLog logs/dummy-host.example.com-access_log common
                                                             </VirtualHost>
Configure IP based Virtual Hosting                    #vim /etc/httpd/conf/httpd.conf
                                                             <VirtualHost 192.168.9.1:80>
                                                             ServerAdmin webmaster@matchine1.example.com
                                                             DocumentRoot /var/www/matchine1-80
                                                             ServerName matchine1.example.com
                                                             #    ErrorLog logs/dummy-host.example.com-error_log
                                                             #    CustomLog logs/dummy-host.example.com-access_log common
                                                             </VirtualHost>
Configure PORT based Virtual hosting                  #vim /etc/httpd/conf/httpd.conf
                                                             Listen 8080
                                                             <VirtualHost 192.168.9.1:8080>
                                                             ServerAdmin webmaster@matchine1.example.com
                                                             DocumentRoot /var/www/matchine1-8080
                                                             ServerName matchine1.example.com
                                                             #    ErrorLog logs/dummy-host.example.com-error_log
                                                             #    CustomLog logs/dummy-host.example.com-access_log common
                                                             </VirtualHost>
Restricting user access
1.Enable authenticaion                                #vim /etc/httpd/conf/httpd.conf
                                                            <VirtualHost *:80>
                                                             ServerAdmin root@www2.example.com
                                                             DocumentRoot /var/www/site3
                                                             ServerName www2.example.com
                                                             DirectoryIndex index.html
                                                            <Directory /var/www/site2>
                                                             Options FollowSymLinks
                                                             AllowOverride Authconfig
                                                            </Directory>
                                                            </VirtualHost>

2.Create .htaccess file in the root directory         #vim /var/www/site3/.htaccess
                                                             AuthName   "restricted user"
                                                             AuthType   Basic
                                                             AuthUserFile      /etc/httpd/conf/vir.passwd
                                                             require          valid-user

3.add user in vir.passwd file                         #htpasswd -mc /etc/httpd/conf/vir.passwd admin
                                                      #htpasswd -c /etc/httpd/conf/vir.passwd anis
4.change vir.passwd file permission for apache        #chgrp apache /etc/httpd/conf/vir.passwd
                                                      #chmod g+r /etc/httpd/conf/vir.passwd
5.Restart the service                                 #service httpd restart

Restricting Network access
Configure access                              #vim /etc/httpd/conf/httpd.conf
                                                            <Directory "/var/www/cgi-bin">
                                                             Order allow,deny
                                                             Allow from 192.168.8.
                                                             Deny from all
                                                            </Directory>
Configuring https server
1.install mod_ssl                                     #yum install mod_ssl -y
2.Edit /etc/httpd/conf.d/ssl.conf                     #vim /etc/httpd/conf.d/ssl.conf
                                                            NameVirtualHost *:443
                                                            <VirtualHost *:443>
                                                            ServerAdmin root@station2.example.com    
                                                            DocumentRoot /var/www/html
                                                            ServerName  station2.example.com
                                                            </VirtualHost>
3.Restart httpd service                               #service httpd restart
4.Add certificate using graphical browser

No comments:

Post a Comment