0% found this document useful (0 votes)
53 views22 pages

Apache Web Service: 69-3 Nguyen Thi Nho, P9, Q.Tbinh, Tp. HCM

The document discusses the Apache web server. It describes how to install Apache from source, configure a basic Apache server, and set up access control and virtual hosts. Specifically, it covers installing Apache by downloading the tarball, compiling, and installing it. It also explains how to start and stop the Apache daemon, and configure the httpd.conf file and virtual hosts.

Uploaded by

m3onh0x84
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views22 pages

Apache Web Service: 69-3 Nguyen Thi Nho, P9, Q.Tbinh, Tp. HCM

The document discusses the Apache web server. It describes how to install Apache from source, configure a basic Apache server, and set up access control and virtual hosts. Specifically, it covers installing Apache by downloading the tarball, compiling, and installing it. It also explains how to start and stop the Apache daemon, and configure the httpd.conf file and virtual hosts.

Uploaded by

m3onh0x84
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

Chapter 18

Apache Web Service

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Objectives

Describe the background of the Apache web


server
Demonstrate installation of Apache from
source
Configure a basic Apache server
Demonstrate basic setup of access control
Recognize basic setup IP-based,name-based
and port-based virtual hosts

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Why Apache ?

Free

Come with all Linux Distribution

Most popular

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Apache Installation

Download tarball file from :


http://httpd.apache.org/dist/
Install :
# tar xvzf apache_1.35.tar.gz
# cd apache_1.35
# ./configure --with-layout=RedHat \
–-enable-module=so
# make
# make install
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Starting and Stopping

Starting :
# /etc/init.d/httpd start
Stopping :
# /etc/init.d/httpd stop

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Basic Tasks To Setup Apache Server

Configure httpd.conf
Launch httpd daemon
Put your website sources (.html files) into
right directory

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Basic Configuration

Configuration files located in /etc/httpd/conf/


directory. We only use httpd.conf - main
configuration file
Log file located in /var/log/httpd/error_log
directory. We can identify the log file by :
# grep ErrorLog /etc/httpd/conf/httpd.conf
ServerType(Unix) : inetd or standalone

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Configure httpd.conf

Listen 12.34.56.78:80
StartServers 5
MinSpareServers 5
MaxSpareServers 20
MaxClients 150 (not exceed 256)
MaxRequestPerChild 1000
ServerAdmin root@localhost
ServerName www.example.com:80
DocumentRoot "/var/www/html"
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Configure httpd.conf

Include /etc/httpd/conf/firstwebsite.conf
UserDir public_html
UserDir disabled root
Order Allow, Deny
Allow from 1.2.3.4
Deny from www.example.org
DirectoryIndex index.html index.php
AccessFileName .htaccess
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Basic Setup Of Access Control

.htaccess files (or "distributed configuration


files") provide a way to make configuration
changes on a per-directory basis. A file,
containing one or more configuration
directives, is placed in a particular document
directory, and the directives apply to that
directory, and all subdirectories there of

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
HTTP Error Codes

Defined in httpd.h
...
#define HTTP_BAD_REQUEST 400
#define HTTP_UNAUTHORIZED 401
#define HTTP_PAYMENT_REQUIRED 402
#define HTTP_FORBIDDEN 403
#define HTTP_NOT_FOUND 404
#define HTTP_METHOD_NOT_ALLOWED 405
#define HTTP_NOT_ACCEPTABLE 406
#define HTTP_INTERNAL_SERVER_ERROR 500
...
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Customize HTTP Error Codes

Use ErrorDocument directive. Syntax :


ErrorDocument error-code document
o Plain text :
ErrorDocument 500 "The server made a boo boo”
o Local redirect :
ErrorDocument 404 /missing.html
o External redirect :
ErrorDocument 402 http://example.com/info.html

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Virtual Host

Name-based Virtual Hosts : More than one


web site per an IP address
IP-based Virtual Hosts : An IP address for
each web site See : http://tldp.org/HOWTO/IP-
Alias/ to set multiple IP addresses to one NIC
for practice.
Port-based Virtual Hosts : More than one web
site per an IP address but on different ports

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Name-based Virtual Host

1) Configure Apache :
NameVirtualHost 12.34.56.7
Include /etc/httpd/conf/firstwebsite.conf
Include /etc/httpd/conf/secondwebsite.conf
2) Configure DNS

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Name-based Virtual Host

#firstwebsite.conf file in /etc/httpd/conf/ directory


<VirtualHost 12.34.56.7>
ServerName www.firstwebsite.com
ServerAdmin [email protected]
ServerAlias firstwebsite.com *.firstwebsite.com
DocumentRoot /home/httpd/firstwebsite/
ErrorLog /var/log/httpd/firstwebsite-error_log
CustomLog /var/log/httpd/firstwebsite-access_log common
</VirtualHost>

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Name-based Virtual Host

#secondwebsite.conf file in /etc/httpd/conf/ directory


<VirtualHost 12.34.56.7> # the same IP address
ServerName www.secondwebsite.com
ServerAdmin [email protected]
DocumentRoot /home/httpd/secondwebsite/
ErrorLog /var/log/httpd/secondwebsite-error_log
CustomLog /var/log/httpd/secondwebsite-access_log
common
</VirtualHost>

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
IP-based Virtual Host

1) Configure Apache :
Include /etc/httpd/conf/firstwebsite.conf
Include /etc/httpd/conf/secondwebsite.conf
2) Configure DNS

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
IP-based Virtual Host

#firstwebsite.conf file in /etc/httpd/conf/ directory


<VirtualHost 12.34.56.7>
ServerName www.firstwebsite.com
ServerAdmin [email protected]
DocumentRoot /home/httpd/firstwebsite/
ErrorLog /var/log/httpd/firstwebsite-error_log
CustomLog /var/log/httpd/firstwebsite-access_log common
</VirtualHost>

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
IP-based Virtual Host

#secondwebsite.conf file in /etc/httpd/conf/ directory


<VirtualHost 12.34.56.78> # the different IP address
ServerName www.secondwebsite.com
ServerAdmin [email protected]
DocumentRoot /home/httpd/secondwebsite/
ErrorLog /var/log/httpd/secondwebsite-error_log
CustomLog /var/log/httpd/secondwebsite-access_log
common
</VirtualHost>

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Port-based Virtual Host

#firstwebsite.conf file in /etc/httpd/conf/ directory


<VirtualHost 12.34.56.7>
ServerName www.firstwebsite.com
ServerAdmin [email protected]
DocumentRoot /home/httpd/firstwebsite/
ErrorLog /var/log/httpd/firstwebsite-error_log
CustomLog /var/log/httpd/firstwebsite-access_log common
</VirtualHost>

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Port-based Virtual Host

#secondwebsite.conf file in /etc/httpd/conf/ directory


<VirtualHost 12.34.56.7:8080> # the same IP but different
port
ServerName www.secondwebsite.com
ServerAdmin [email protected]
DocumentRoot /home/httpd/secondwebsite/
ErrorLog /var/log/httpd/secondwebsite-error_log
CustomLog /var/log/httpd/secondwebsite-access_log
common
</VirtualHost>

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Summary

Describe the background of the Apache web


server
Demonstrate installation of Apache from
source
Configure a basic Apache server
Demonstrate basic setup of access control
Recognize basic setup IP-based, namebased
and port-based virtual hosts

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102

You might also like