Professional Documents
Culture Documents
Apache Cheatsheet
Apache Cheatsheet
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 Hosting
is a method that servers
such as webservers use to host more than one domain name on
the same computer, sometimes on the same
IP address.
===
Types of Virtual Hosts
==
There are two types of virtual hosts:
1.IP-based
2. Name based ( non-IP-based )
1 [ IP based ]
The former is where each virtual host has its own IP address. You will need a n
ew IP address
for each
virtual host you want to set up, either from your existing allocation or by obta
ining
Setup I - IP based
virtual hosting.
-[ 1 ]
-->Edit apache config file
# vi /etc/httpd/conf/httpd.conf
LINE 56
ServerRoot "/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 312
DocumentRoot "/var/www/html"
# LINE 401
DirectoryIndex index.html
read
#--[ 2 ]--#
# chmmod 755 /var/www/html/
#--[ 3 ]--#
--> Create default index page for the website by the named "index.html" under /v
ar/www/html
# chmod 644 /var/www/html/index.html
#--[ 4 ]--#
# service httpd restart
#-[ 5 ]--#
# chkconfig --level 35 httpd on
# make httpd start on bootup
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.10.30
<VirtualHost 192.168.10.30:80>
ServerName linobox.com
ServerAlias www.linobox.com
ServerAdmin nouresh@linobox.com
DocumentRoot /var/www/html/linobox.com
ErrorLog logs/linobox.com-error_log
CustomLog logs/linobox.com-access_log
common
</VirtualHost>
You could use the above to repeat for more virtual hosts (only <VirtaulHost *> s
ection )
Step 2-5 from Setup
Setup III - IP Based Virtual Hosts
--> Create IP alias
# 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
<VirtualHost 192.168.10.30:80>
ServerName linobox.com
ServerAlias www.linobox.com
ServerAdmin nouresh@linobox.com
DocumentRoot /var/www/html/linobox.com
ErrorLog logs/linobox.com-error_log
CustomLog logs/linobox.com-access_log common
</VirtualHost>
NameVirtualHost 192.168.10.100
<VirtualHost 192.168.10.100:80>
ServerName cryptonys.com
ServerAlias www.cryptonys.com
ServerAdmin nouresh@cryptonys.com
DocumentRoot /var/www/html/cryptonys.com
ErrorLog logs/cryptonys.com-error_log
CustomLog logs/cryptonys.com-access_log common
</VirtualHost>
############################################
Setup password protection - inside httpd.conf
############################################
#
vi /etc/httpd/conf/httpd.conf
<Directory /var/www/linobox_secure>
AuthName
"Restricted Site"
# This would be shown before entering the site
AuthType
# Type of Authentication
Basic
AuthUserFile
/etc/httpd/htpasswd
require valid-user</Directory>
# 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
############################################
-->
Edit Configuration file
# vi /etc/httpd/conf/httpd.conf
<Directory /var/www/chan>
AllowOverrride AuthConfig
</Directory>
-->
Edit htaccess files
# vi /var/www/chan/.htaccess
AuthName "User Restriction"
AuthType Basic
AuthUserFile /etc/httpd/htpasswd
require valid-user
# chmod 640 /var/www/chan/.htaccess
# chgrp apache /var/www/chan/.htaccess
--> make accessible for reading
# chmod g+r /etc/httpd/htpasswd
--> adds the user "chan" to the
password file "/etc/httpd/htpasswd"
# htpasswd -m /etc/httpd/htpasswd chan
############################################
Setup host-based access restrictions
Edit Configuration file
# vi /etc/httpd/conf/httpd.conf
<Directory /var/www/sheena>
Order allow, deny
# explicitly allow
Allow from linobox.com
# allow from allows the hosts
</Directory>
<Directory /var/www/lino>
Order deny, allow
# explicitly allow
Deny from xxx.com
# deny from this host
</Directory>