Thursday, June 25, 2009

Apache Web Server Notes

For an Apache web server the combinations you would use are:

SAMP - Solaris Apache MySQL PHP/Perl
LAMP - Linux Apache MySQL PHP/Perl/Python

Modular & Reliable

2 Versions (1.3.33 & 2.0.50) are included with Solaris 10
svcs -a | grep -i apache

Note: Apache2 documentation is available @: http://localhost/manual
Steps to invoke Apache on Solaris 10:
1. cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
2. update servername & server admin directives for main server
3. svcadm enable apache2
4. netstat -anP tcp | grep 80 && http://localhost/manual

Note: Typical classes of web server errors:
200 - OK
300 - Redirect
400 - client error
500 - server errors

Note: Apache ALWAYS maintains a DEFAULT HOST. Config is in httpd.conf and outside of ANY and ALL virtual hosts containers
Note: Apache requires the following info. for the DEFAULT HOST:
1. ServerName linuxcbtsun1.linuxcbt.internal
2. ServerAdmin
3. DocumentRoot - where to serve content from
4. IP Address:Port to bind to - optional
5. Logging information - custom/combined & error logs


Note: Listen directive controls IPs and ports that Apache binds to
Note: specify 'Listen' directive(s) in the DEFAULT HOST(httpd.conf)
Note: You can specify multiple Listen Directives
Note: Apache binds to ALL IP addresses when 'Listen' is specified without an IP address

DEFAULT HOST(IP:PORT)
-Virtual Host 1
-Virtual Host 2


<Directory "/var/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "/var/apache2/htdocs/temp">
Options FollowSymLinks
AllowOverride None

Order allow,deny
Allow from all
</Directory>

Note: <Directory "/var/apache2/htdocs"> - applies to all sub-directories

###Order, Allow, Deny Rules###
Note: Order is specified and Deny or Allow or combination follows
Note: Allow|Deny supports the following attributes
1. IP Address - 127.0.0.1
2. IP Address range
3. IP Subnet Mask using CIDR or Class notation - 192.168.1.0/24 or 192.168.1.0/255.255.255.0
4. 192.168.1
5. ALL
6. Environment variables - referrer, user agents

Used to influence default doc: DirectoryIndex index.html index.html.var

LogFormat is used to define logging keywords that can be referenced
Apache can log to multiple log files, various keywords, simultaneously

###Alias Directive###
Maps webspace location to file system location, usually non-document root


###Files Directive###
Facilitates restrictions on matchings files regardless of location on server
<Files noaccess.html>
Order allow,deny
Deny from all
</Files>
Note: When applied OUTSIDE of <Directory> block, applies to all instances of named file throughout the web server

Task: Create web-accessible directory, but, restrict access to certain IPs
Steps:
1. mkdir /var/apache2/private
2. Create appropriate Alias - Alias /private/ /var/apache2/private/
3. Create appropriate <Directory> block


###Virtual Hosts Support###
2 Types of Virtual Hosts are supported:
1. IP-based - Each virtual host is associated with a distinct address
2. Name Based - All or a group of Virtual Hosts share a distinct address


###IP-based Virtual Hosting###
Note: System requires multiple IP addresses
Note: Default Apache Host binds to ALL IP addresses on port 80

Steps:
1. Implement appropriate 'Listen' directive
2. Configure Virtual Hosts
3. Restart Apache
4. Test configuration

Listen 192.168.1.50:80
<VirtualHost 192.168.1.50:80>
ServerName linuxcbtsun1.linuxcbt.internal
ServerAdmin unixcbt@linuxcbtsun1.linuxcbt.internal
DocumentRoot /var/apache2/ipvhost1
ErrorLog /var/apache2/logs/ipvhost1.error.log
CustomLog /var/apache2/logs/ipvhost1.access.log
</VirtualHost>
Note: Apache will serve content from the DocumentRoot of DEFAULT HOST if a request does NOT match any of the Virtual Hosts


Listen 192.168.1.51:80
<VirtualHost 192.168.1.51:80>
ServerName linuxcbtsun3.linuxcbt.internal
ServerAdmin unixcbt@linuxcbtsun1.linuxcbt.internal
DocumentRoot /var/apache2/ipvhost2
ErrorLog /var/apache2/logs/ipvhost2.error.log
CustomLog /var/apache2/logs/ipvhost2.access.log combined
</VirtualHost>


###NameBased Virtual Hosting###
Facilitates the sharing of 1 IP address by a group of web sites
Steps:
1. Define appropriate Listen directive(s)
2. Define appropriate NameVirtualHost directive(s)
3. Define Virtual Hosts
4. Restart Apache
5. Confirm configuration

Listen 80
NameVirtualHost *:80 - means to permit NameBased Virtual Hosts on ALL IPs
Note: NameVirtualHost directive MUST match VirtualHost directive

<VirtualHost *:80>
ServerName linuxcbtsun1.linuxcbt.internal
ServerAdmin unixcbt@linuxcbtsun1.linuxcbt.internal
DocumentRoot /var/apache2/namevhost1
ErrorLog /var/apache2/logs/namevhost1.error.log
CustomLog /var/apache2/logs/namevhost2.access.log combined
</VirtualHost>

Readers who read this page, also read:




Bookmark and Share My Zimbio http://www.wikio.com

0 comments: