Sie sind auf Seite 1von 20

APACHE TRAINING:

================

Apache is an open-source (source code is freely available and can be shared)


HTTP Web server software. It is currently the most popular web server on the
Net. It is usually run on UNIX operating system versions like Linux or BSD, but it
can also be run on Windows. It is a full-featured server with many powerful add-
ons freely available.

Apache Versions Available:


====================

Version 1.3
Version 2.0
Version 2.2

Apache features:
============

1. Virtual Hosting

2. Dynamic Apache Module Support

3. Implements the latest protocols, including HTTP/1.1

HTTP (for HyperText Transfer Protocol) is the primary method used to transfer information on the World
Wide Web. The original purpose was to provide a way to publish and receive HTML pages.

4. It is highly configurable and extensible with third-party modules

5. Provides full source code and comes with an unrestrictive license

6. Runs on Windows NT/9x, Netware 5.x and above, OS/2, and most versions of UNIX,
as well as several other operating systems

7. Implements many frequently requested features, like Virtual Hosts, Multiple Directory
Indexes.
Apache Installations:
===============

1. Download the source code $ lynx http://httpd.apache.org/download.cgi

2. Extract $gzip -d httpd-2_0_NN.tar.gz


$ tar xvf httpd-2_0_NN.tar

3. Configure environment to compile apache

 cd apache

 ./configure - -prefix= path (/usr/local/apache/)


-- enable-<module>
--enable–modules= < module list>
--disable-<module>
4. Build the package

Now you can build the various parts which form the Apache package by simply running
the command

Now you can build the various parts which form the Apache package.

 make

5. Install
Now its time to install the package under the configured installation PREFIX (see the
--prefix option above):
Now it's time to install the package under the configured installation.

 make install

Install Apache using binary:


============================

1. First check whether apache is already installed using the command


and then go head with the installation

rpm –qa | grep httpd


2. Then download the following rpms

http://download.fedora.redhat.com/pub/fedora/linux/core/5/i386/os/Fedora
/RPMS/httpd-2.2.0-5.1.2.i386.rpm

http://download.fedora.redhat.com/pub/fedora/linux/core/5/i386/os/Fedora
/RPMS/httpd-devel-2.2.0-5.1.2.i386.rpm

http://download.fedora.redhat.com/pub/fedora/linux/core/5/i386/os/Fedora
/RPMS/httpd-manual-2.2.0-5.1.2.i386.rpm

3. Install it using the command

rpm -ivh httpd-2.2.0-5.1.2.i386.rpm

rpm -ivh httpd-2.2.0-5.1.2.i386.rpm

rpm -ivh httpd-2.2.0-5.1.2.i386.rpm

Requirements
The following requirements exist for building Apache:

Disk Space
Make sure you have at least 50 MB of temporary free disk space available. After
installation Apache occupies approximately 10 MB of disk space. The actual disk
space requirements will vary considerably based on your chosen configuration
options and any third-party modules.

ANSI-C Compiler and Build System


Make sure you have an ANSI-C compiler installed. The GNU C compiler (GCC)
from the Free Software Foundation (FSF) is recommended (version 2.7.2 is fine).
If you don't have GCC then at least make sure your vendor's compiler is ANSI
compliant. In addition, your PATH must contain basic build tools such as make.

Perl 5 [OPTIONAL]

For some of the support scripts like apxs or dbmmanage (which are written in
Perl) the Perl 5 interpreter is required (versions 5.003 or newer are sufficient). If
you have multiple Perl interpreters (for example, a systemwide install of Perl 4,
and your own install of Perl 5), you are advised to use the --with-perl option
(see below) to make sure the correct one is used by configure. If no Perl 5
interpreter is found by the configure script, you will not be able to use the affected
support scripts. Of course, you will still be able to build and use Apache 2.0.

Modules used:
============

1. For URI to file name translation phase:


mod_userdir  It is used to set user-specific directories

mod_rewrite  It provides a rules bases rewriting engine to rewrite URL’s on


the fly.

2. For authentication / authorization phases


mod_auth  This module allows the use of HTTP Basic Authentication to restrict
access by looking up users in plain text password and group files.

mod_access  It provides access based on client hostname, ip-address and other


characterstics of client request.

3. For determining the MIME type of the requested object


mod_mime  Associates the requested filename's extensions with the file's
behavior (handlers and filters) and content (mime-type, language,
character set and encoding)

mod_mime_magic Determines the MIME type of a file by looking at a few


bytes of its contents.

4. For sending actual data back to the client


mod_actions  This module provides for executing CGI scripts based on media .
type or request method.

mod_asis  This module provides the handler send-as-is which causes Apache
to send the document without adding most of the usual HTTP
headers.

mod_autoindex  Generates directory indexes, automatically, similar to the Unix


ls command.

mod_cgi  This module provides for execution of CGI scripts.

mod_include  Server-parsed html documents.(server side includes)


mod_dir  Provides for "trailing slash" redirects and serving directory index files

mod_imap  Server-side imagemap processing

5. For logging the request phase:


mod_alias  Provides mapping different parts of the host filesystem in the
document tree and for URL redirection.

mod_env  Modifies the environment which is passed to CGI scripts and SSI
pages.

mod_speling  Attempts to correct mistaken URLs that users might have


entered by ignoring capitalization and by allowing up to one
misspelling.

6. For security
mod_ssl  It is a security module that provides strong cryptography, which
implements SSL/TLS using “openssl” libraries.

Basic Configuration:
===============

Path of the installed directory for

Binary: /etc/httpd/

Source: It depends on your PREFIX, but the default is /usr/local/apache

 Section 1: Global Environment

 Section 2 : main server configuration

 Section3 : virtual host

Global Environment:

 The ServerRoot directive is where the configuration files, error logs, and
access files are stored (normally the log and error directories are symbolic links to
another location), you probably don't want to change this setting.
ServerRoot "/usr/local/apache"

 PidFile names the file where the server records its process ID (PID).

PidFile “logs/httpd.pid”

 Timeout defines, in seconds, the amount of time that the server will wait for
receipts and transmissions during communications. Specifically, Timeout defines
how long the server will wait to receive a GET request, how long it will wait to
receive TCP packets on a POST or PUT request, and how long it will wait
between ACKs responding to TCP packets.

“Timeout 300”

 KeepAlive sets whether the server will allow more than one request per
connection and can be used to prevent any one client from consuming too much
of the server’s resources.

“KeepAlive on”

 This directive sets the maximum number of requests allowed per persistent
connection

“MaxKeepAliveRequesta 100”

 KeepAliveTimeout sets the number of seconds the server will wait after a request
has been served before it closes the connection.

“KeepAliveTimeout 15”

 The Apache HTTP Server dynamically adapts to the perceived load by


maintaining an appropriate number of spare server processes based on the traffic.

 StartServers sets how many server processes are created upon startup.

 MaxClients sets a limit on the total number of server processes, or simultaneously


connected clients, that can run at one time. The main purpose of this directive is to
keep a runaway Apache HTTP Server from crashing the operating system

 MaxRequestsPerChild sets the total number of requests each child server process
serves before the child dies.
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 20
MaxRequestPerChild 0
</IfModule>

 The Listen command identifies the ports on which the Web server will accept
incoming requests. By default, the Apache HTTP Server is set to listen to port 80
for non-secure Web communications and (in the /usr/local/apache/conf.d/ssl.conf
which defines any secure servers) to port 443 for secure Web communications.

“Listen 80” (for non-secure Web communications)

“Listen 443” (for secure Web communications)

 LoadModule is used to load in Dynamic Shared Object (DSO) modules

“LoadModule foo_module modules/mod_foo.so”

 The ExtendedStatus directive controls whether Apache generates basic (off) or


detailed server status information (on), when the server-status handler is called.
The Server-status handler is called using Location tags.

“ExtendedStatus On”

Main Server Configuration:

 The User directive sets the user name of the server process and determines what
files the server is allowed to access

“User apache”

 The Group directive Specifies the group name of the Apache HTTP Server
processes.

“Group apache”
 You may want to change the server admin email address . Set the ServerAdmin
directive to the email address of the Web server administrator. This email address
will show up in error messages on server-generated Web pages, so users can
report a problem by sending email to the server administrator.
Default: root@localhost

“ServerAdmin admin@example.com”

 Use ServerName to set a hostname and port number (matching the Listen
directive) for the server. The ServerName does not need to match the machine’s
actual hostname

“ServerName www.example.com:80”

 The DocumentRoot is the directory which contains most of the HTML files which
is served in response to requests.

“DocumentRoot /usr/local/apache/htdocs”

 With the above source installation of apache the apache conf file is created at

“/usr/local/apache/conf/httpd.conf”

 If you want to run Apache on a different port to the default (80) then then change
the number. Ports less than 1023 will require Apache to be started as root. Port
80 is probably the easiest to use since all other ports have to be specified
explicitly in the web browser, eg: http://localhost:81.

“Port 80”

 Using Directory directive we can enclose a group of directives that will apply to a
specific directory.
 The Options directive controls which server features are available in a particular
directory.

 The AllowOverride directive sets whether or not any Options can be overridden
by the declarations in an .htaccess file. By default, both the root directory and the
DocumentRoot are set to allow no .htaccess overrides.

 The Order directive controls the order in which allow and deny directives are
evaluated.
 Allow specifies which requester can access a given directory. The requester can
be all, a domain name, an IP address, a partial IP address, a network/netmask pair,
and so on.

 Deny works just like Allow, except it specifies who is denied access.

<Directory “/usr/local/apache/htdocs”>

Options Indexes FollowSymLinks

AllowOverride None

Order Allow, Deny

Allow from all

</Directory>

 UserDir is the name of the subdirectory within each user’s home directory where they
should place personal HTML files which are served by the Web server.

“UserDir public_html”

 The DirectoryIndex is the default page served by the server when a user requests an
index of a directory by specifying a forward slash (/) at the end of the directory name.

“DirectoryIndex index.htm index.html index.php

 AccessFileName names the file which the server should use for access control
information in each directory. The default is .htaccess.

“AccessFileName .htaccess”

 HostnameLookups can be set to on, off or double. If HostnameLookups set to on, the
server automatically resolves the IP address for each connection. Resolving the IP
address means that the server makes one or more connections to a DNS server,
adding processing overhead. To conserve resources on the server, HostnameLookups
set to off by default.

“HostnameLookups Off”
 ErrorLog specifies the file where server errors are logged.

“ErrorLog logs/error_log”

 LogLevel sets how verbose the error messages in the error logs are.

“LogLevel warn”

 The LogFormat directive configures the format of the various Web server log files.

“LogFormat "%h %l %u %t \"%r\" %>s %b" common”

 CustomLog identifies the log file and the log file format.

“CustomLog logs/access_log common”

 The Alias setting allows directories outside the DocumentRoot directory to be


accessible. Any URL ending in the alias automatically resolves to the alias’ path.

Alias /first/ "/tmp/first/public"

 The ScriptAlias directive defines where CGI scripts are located.

ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"

 When a web page is moved, Redirect can be used to map the file location to a new
URL.

“Redirect permanent /foo http://www.example.com/bar”

 Use the AddType directive to define MIME type and file extension pairs. For
example, using PHP4, use the AddType directive to make the Web server recognize
with PHP file extensions (.php4, .php3 .phtml .php) as PHP MIME types.

AddType text/html .shtml


AddHandler server-parsed .shtml

 AddHandler maps file extensions to specific handlers.


AddHandler cgi-script .cgi

 The ErrorDocument directive associates an HTTP response code with a message or a


URL to be sent back to the client.

ErrorDocument 404 /missing.html

Virtual Hosts:

The virtual host tags create a container outlining the characteristics of a virtual host.

1. Ip-based virtual host

2. Name based virtual hosts

Name based virtual hosts: Number of servers on same ip-address.

NameVirtualHost <ip>:<port>

<VirtualHost <ip>/<name>>

ServerName www.example.com

DocumentRoot /home/raju/public_html

</VirtualHost>

IP Based virtual host:

One IP one server

SSL requires IP based virtual hosting

<VirtualHost ip:port>

ServerAdmin webmaster@cts.com

ServerName www.cts.com
DocumentRoot /home/ram/public_html

</VirtualHost>

Modules:

1. Installing third party modules.

2. Apxs apache extension module

cd /path/to/3rdparty

apxs -c mod_foo.c

apxs -i -n foo mod_foo.so

Edit http.conf

LoadModule foomodule modules/mod_foo.so

3. If configure script is provided by the package run

./configure –with-apxs=/usr/local/apache/bin/apxs

Make

Make install

Update httpd.conf

Modules type:

 Static modules
 Dynamic modules

Static modules

mod_dir
mod_imap

mod_include

mod_log_agent

mod_log_config

mod_log_referer

mod_mime

mod_so.c

mod_userdir ….

Dynamic shared modules:

mod_proxy

mod_rewrite

mod_speling

mod_perl

mod_php4

mod_jk

LoadModule module filename

eg: LoadModule jk_module modules/mod_jk.so

Mod_proxy :

 proxy/cache for Apache


 proxying capability for FTP, HTTP/0.9 ,1.0,1.1

 Forward and reverse proxy configurations

Forward Proxy:
ProxyRequests On

ProxyVia On

<Proxy *>

Order deny,allow

Deny from all

Allow from internal.example.com

</Proxy>

Reverse Proxy:

ProxyRequests Off

<Proxy *>

Order deny,allow

Allow from all

</Proxy>

ProxyPass /foo http://foo.example.com/bar

ProxyPassReverse /foo http://foo.example.com/bar

Mod_jk:

Used to integrate apache and tomcat.

Configuration:

LoadModule jk_module modules/mod_jk.so


JkWorkersFile conf/workers.properties

JkLogFile logs/modjk.log

JkLogLevel info

JkMount /*.jsp ajp13

JkMount /servlet/* ajp13

Mod_rewrite:

URL Rewriting engine

 Urls to urls
 Urls to filename

 Filename to filename

Configuration:

LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine on

RewriteOptions MaxRedirects=10

Inherits (inherits from parent virtual host case)

RewriteLog <filename>

RewrietLoglevel 0

RewriteBase /xyz (sets base url for per-directory rewrites. It is put under a directory
eg: /abc/def)

RewriteCond : <teststring> <condpattern>

teststring: ????

RewriteRule backreferences

RewriteCond backreferences

RewriteMap expansions
Server-variables %{name of varible}

Mod_cgi:

Configuration:

LoadModule cgi_module modules/mod_cgi.so

mime type application/x-httpd-cgi or

Addhandler cgi-script .cgi

ScriptLog logs/cgi_log

ScriptLogBuffer bytes (Maximum amount of PUT or POST requests that will be


recorded in the scriptlog )

ScriptLogLength bytes (Size limit of the CGI script logfile )

ScriptAlias /cgi-bin/ /usr/local/apache/cgi-bin/

(Maps a URL to a filesystem location and designates the target as a CGI script )

Mod_php:

Configuration:

./configure –prefix=/usr/local/php --with-apxs=/usr/local/apache/bin/apxs

make

make install
In httpd.conf make the following changes,

LoadModule php_module modules/mod_php.so LoadModule php3_module


modules/libphp3.so LoadModule php4_module modules/libphp4.so

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

AddType application/x-httpd-php3 .php3

SSL (Secure Socket Layer)

 SSL is a technology that allows web browsers and web servers to communicate
over a secured connection.
 The data being send is encrypted by one side, transmitted, then decrypted by the
other side before processing.

 Another Important aspect of SSL protocol is Authentication.

Implementing ssl onapache using mod_ssl:

Apache + mod_ssl + OpenSSL

Apache must be install with --enable-ssl

mod_ssl is security module for Apache server. It provides strong cryptography for the
apache server via Secure Socket Layer (SSL) and Transport Layer Security (TSL)
protocols.

Certificates and Security:

Secure Server provides security using a combination of the SSL protocol and Digital
Certificate.

Self Signed Certificate

Certificate from Certificate Authority (CA)

Eg: verisign, thawte

Creating Certificates:

Generating a private key.


openssl genrsa –des3 –out www.cts.com.key 1024

You will be asked to enter pass phrase to encrypt the private key with it.

Generating a certificate signing request.

openssl req –new –key www.cts.com.key –out www.cts.com.csr

Send the csr to CA.

You will be asked to enter pass phrase for the private key.

Generating a self signed certificate:

openssl req –new –key www.cts.com.key -x509 –out www.cts.com.csr

You will be asked to enter pass phrase for the private key.

Ensure that the private key file is in the directory that you have chosen to use

/usr/apache/conf/ssl.key

Ensure that the CA-signed or self-signed certificate is in its designated location

/usr/apache/conf/ssl.crt

Configuration:

Compile and install apache with --enable-module=ssl

In httpd.conf

<IfDefine SSL>

Listen 80

Listen 443

</IfDefine SSL>

<IfDefine SSL>

<VirtualHost _default_:443>

DocumetRoot /var/www/
ServerName www.cts.com

SSLEngine on

SSLCertificateFile conf/ssl.crt/server.crt

SSLCertificateKeyFile conf/ssl.key/server.key

</VirtualHost>

</IfDefine SSL>

Staring and stopping apache server:

/usr/local/apache/bin/apachectl start

/usr/local/apache/bin/apachectl stop

Status codes:

Informal 1xx

Provisional response

Successful 2xx

the request has succeeded

Redirection 3xx

Further action need to be taken by the user agent.

300 HTTP_MULTPLE_CHOICE

301 HTTP_MOVED_ERMANENTLY

302 HTTP_MOVED_TEMPORARILY

303 HTTP_SEE_OTHER

304 HTTP_NOT_MODIFIED

305 HTTP_USE_PROXY
Client Error 4xx

Client seems to be erred.

400 Bad request

401 Unauthorized

402 payment required

403 forbidden

404 Not Found

407 proxy authentication required

Server Error 5xx

Server is aware that it has erred or is incapable of performing the request.

500 Internal Server Error

501 Not Implemented

502 Bad Gateway

503 Service Unavailable

504 Gateway time out.

Das könnte Ihnen auch gefallen