Upload
vinod-nalawade
View
216
Download
0
Embed Size (px)
Citation preview
7/24/2019 Apache Cheatsheet
1/7
================================Packages================================-httpd- redhat-config-httpd (RHELAS3)- system-config-httpd (RHELAS4/FC4/FC5)- httpd-manual
================================Files================================-/etc/httpd/conf/httpd.conf-/etc/httpd/conf.d/*-/etc/httpd/conf.d/ssl.conf- .htaccess
================================
Daemons==- httpd
############################################
Virtual Hostingis a method that servers
such as webservers use to host more than one domain name onthe same computer, sometimes on the sameIP address.
===
Types of Virtual Hosts==
There are two types of virtual hosts:
1.IP-based2. Name based ( non-IP-based )
1 [ IP based ]
The former is where each virtual host has its own IP address. You will need a new IP addressfor eachvirtual host you want to set up, either from your existing allocation or by obtaining
7/24/2019 Apache Cheatsheet
2/7
more from your service provider.Once you have extra IP addresses, you tell your machine tohandle them. On some operating systems, you can give asingle ethernet interface multiple addresses(typically with an ifconfig alias command). On other systems you will haveto have a differentphysical interface for eachIP address (typically by buying extra ethernet cards).
-[ Name based ]--
IP addresses are a resource that costs moneyand are increasingly difficult to get hold of,so modern browsers can now also use 'non-IP' virtual hosts. This lets youuse the same IP addressfor multiple host names.
Name based virtual hosts is used for hosting multiple websites on thesame webserver IP address.
Setup I - IP basedvirtual hosting.
-[ 1 ]
-->Edit apache config file# vi /etc/httpd/conf/httpd.conf
LINE 56ServerRoot "/etc/httpd"
# Filenames that do "not" begin with "/", the value of ServerRoot
# is prepended, i.e. /etc/httpd
# LINE 272
ServerName www.linobox.com:80# Decomment it, enter the servername
# LINE 312DocumentRoot "/var/www/html" # set folder for the webpages
# LINE 401DirectoryIndex index.html # set the name of the file that is first
read
7/24/2019 Apache Cheatsheet
3/7
#--[ 2 ]--## chmmod 755 /var/www/html/
#--[ 3 ]--#--> Create default index page for the website by the named "index.html" under /var/www/html
# chmod 644 /var/www/html/index.html
#--[ 4 ]--## service httpd restart
#--[ 5 ]--## chkconfig --level 35 httpd on# make httpd start on bootup
Setup II - Name Based Virtual Hosts####
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.10.30
ServerName linobox.com
ServerAlias www.linobox.comServerAdmin [email protected]
DocumentRoot /var/www/html/linobox.com
ErrorLog logs/linobox.com-error_logCustomLog logs/linobox.com-access_log
common
You could use the above to repeat for more virtual hosts (only s
ection )
-
Step 2-5 from Setup
Setup III - IP Based Virtual Hosts
--> Create IP alias
7/24/2019 Apache Cheatsheet
4/7
# cd /etc/sysconfig/network-scripts/#
cp ifcfg-eth0 ifcfg-eth0:0# vi ifcfg-eth0:0
DEVICE=eth0:0
BOOTPROTO=static
BROADCAST=192.168.10.255
IPADDR=192.168.10.200
NETMASK=255.255.255.0
NETWORK=192.168.10..0
ONBOOT=yes
-->
edit config file
#vi /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.10.30
ServerName linobox.com
ServerAlias www.linobox.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/linobox.com
ErrorLog logs/linobox.com-error_log
CustomLog logs/linobox.com-access_log common
# repeat for all other virtual hosts
NameVirtualHost 192.168.10.100ServerName cryptonys.comServerAlias www.cryptonys.com
ServerAdmin [email protected]
7/24/2019 Apache Cheatsheet
5/7
DocumentRoot /var/www/html/cryptonys.comErrorLog logs/cryptonys.com-error_log
CustomLog logs/cryptonys.com-access_log common
############################################
Setup password protection - inside httpd.conf
############################################
#vi /etc/httpd/conf/httpd.conf
AuthName
"Restricted Site" # This would be shown before entering the site
AuthType Basic# Type of Authentication
AuthUserFile /etc/httpd/htpasswdrequire valid-user
# useradd nouresh
# passwd nouresh
--> Create Passwd file
# touch /etc/httpd/htpasswd
-->Change group ownership of password file
# chgrp apache /etc/httpd/htpasswd
-->make accessible for reading# chmod g+r /etc/httpd/htpasswd
--> adds the user "nouresh" to the password file
"/etc/httpd/htpasswd"# htpasswd -m /etc/httpd/htpasswd nouresh
############################################Setup password protection - .htaccess############################################
7/24/2019 Apache Cheatsheet
6/7
7/24/2019 Apache Cheatsheet
7/7
Order deny, allow
# explicitly allow
Deny from xxx.com# deny from this host