apache web server installation/configuration, virtual hosting

24
06/26/22 C. Edward Chow CS4 01 Pag e 1 Apache Web Server A PAtCHy server: developed by the Apache group formed 2/95 around a number of people who provided patch files for NCSA httpd 1.3 by Rob McCool. • History-http://www.apache.org/ABOUT_APACHE.html First official public release (0.6.2) in April 1995 Add adaptive pre-fork child processes (very important!). Modular structure and API for extensibility (Bob Thau) Port to multiple platforms. Add documentation. Apache 1.0 was released on 12/1/95. Pass NCSA httpd to be #1 server in Internet.

Upload: webhostingguy

Post on 19-May-2015

1.665 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 1

Apache Web Server

• A PAtCHy server: developed by the Apache group formed 2/95 around a number of people who provided patch files for NCSA httpd 1.3 by Rob McCool.

• History-http://www.apache.org/ABOUT_APACHE.html• First official public release (0.6.2) in April 1995• Add adaptive pre-fork child processes (very important!).• Modular structure and API for extensibility (Bob Thau)• Port to multiple platforms. Add documentation.• Apache 1.0 was released on 12/1/95.

Pass NCSA httpd to be #1 server in Internet.

Page 2: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 2

Web Server Installation Statistics

• http://www.netcraft.co.uk/survey/

Page 3: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 3

Compiling Apache_1.3.12• Download apache_1.3.12.tar.gz from

http://www.apache.org/dist or closer mirror sites• $tar xzvf apache_1.3.12.tar.gz• $ ./configure --prefix=PREFIX• $ make• $ make install• $ PREFIX/bin/apachectl start

• Here PREFIX is the prefix of the directory containing the distribution, typically it is /usr/local/apache.

Page 4: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 4

CS401 Apache Testbed• bilbo.uccs.edu and frodo.uccs.edu are installed with

Apache1.3.12.• /mpc/home/www/sites contains the configuration files

of various web sites contained in the CD-ROM of Apache text.

• See http://cs.uccs.edu/~cs401/cs401lab.html for more detail on how to carry out the exercise.

• Copy /mpc/home/www/sites to your directory.• To avoid conflict, use port # = 8<last 3 digits of SS#>

Add “Port 8<last 3 digits of SS#>“ to httpd.conf.

Page 5: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 5

Apache Exercise Setup• Replace domain name/IP address on 3rd left Linux PC

www.butterhlies.com 192.168.123.2 with bilbo.uccs.edu 128.198.192.182 sales.butterthlies.com 192.168.123.3 with b2b.uccs.edu 128.198.192.172www.faraway.com 192.168.124.1 with wait.uccs.edu 128.198.192.202

• Replace domain name/IP address on 4th left Linux PCwww.butterhlies.com 192.168.123.2 with frodo.uccs.edu 128.198.192.183 sales.butterthlies.com 192.168.123.3 with feline.uccs.edu 128.198.192.173www.faraway.com 192.168.124.1 with walden.uccs.edu 128.198.192.203

• Replace domain name/IP address on 5th left Linux PCwww.butterhlies.com 192.168.123.2 with gandalf.uccs.edu 128.198.192.194 sales.butterthlies.com 192.168.123.3 with gallop.uccs.edu 128.198.192.174www.faraway.com 192.168.124.1 with wind.uccs.edu 128.198.192.204

Page 6: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 6

Apache Testbed: LAN Setup

• /usr/www/lan_setup script for bilbo:

ifconfig eth0 128.198.192.182

ifconfig eth0:0 128.198.192.172

ifconfig eth0:1 128.198.192.202• Or on linuxconf for bilbo, select

config | networking | IP aliases for virtual hosts | eth0. Type in 128.198.192.172, 128.198.192.202 for IP aliases(I have not succeeded in using the above method.)

• Normally we skip lan_setup. We will share the same lan_setup. Run the above lan_setup if you find the computer is configured incorrectly (through ifconfig).

Page 7: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 7

Ifconfig command

• Interface configuration command.• There is an equivalent command ipconfig on win32.• In Redhat linux, it is in /sbin. I have modified

/etc/profile to include that directory in $PATH.• Use ifconfig to show the status• Use ifconfig eth0:1 down to shut down the IP aliase.• Use ifconfig eth0:1 up to bring it up again.

Page 8: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 8

Apache Web Site Exercises • Each site.<exercise> directory contains

– conf: configuration files, httpd.conf, srm.conf, access.conf, mime.types

– htdocs: contains web pages, scripts– logs: access_log, error_log, httpd.pid, (referer_log, agent_log) – go: alias of “httpd -d xxSITESxx/site.<name> -X”

-d for the site directory, -X single process execution• Edit the httpd.conf file. Add the following lines

Port 8<last 3 digits of your SS#> TransferLog /mpc/home/<login>/sites/site.<name>/logs/access_log

• In go shell script file, replace xxSITESxx with /mpc/home/<login>/sitesreplace <name> with the corresponding site name.

• Type go to start the web server

Page 9: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 9

Examine httpd Configuration• To enhance the security, webuser is created to run httpd

Add “User webuser” and “Group webgroup” to httpd.conf.• “tail -f <site>/logs/error_log” or “ps aux | grep webuser” to

see if the server is configured and running.[Sat Feb 7 20:23:57 1998] Server configured -- resuming normal operations orwebuser 13013 0.0 2.2 1260 704 ? S 20:23 0:00 httpd -d /home/cs401

• “tail -f <site>/logs/access_log” to see the processing results of client requestsusrp16.uccs.edu - - [07/Feb/1998:03:21:16 -0700] "GET / HTTP/1.0" 200 170

• Use a browser (on vinci or other machines) to accessthe server a few times with url = http://bilbo:8345/

• “kill `cat <site>/logs/httpd.pid`” to terminate web server.note that it is back quote ` and not ‘

Page 10: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 10

Httpd Configuration File

• Apache uses a set of (73) directives to describe to httpd how the web site should be configured. http://www.apache.org/docs/mod/directives.html

Each Apache configuration directive is described using a common format that looks like this:

Syntax: directive-name some args Default: directive-name default-value Context: context-list Override: override Status: status Module: module-name

Compatibility: compatibility notes

Page 11: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 11

Block Directives

• Directives that limit the application of other directives.• Specify by a group like a tag section in html.• <VirtualHost host[:port]>

...</VirtualHost>

• <VirtualHost…><Directory dir>, <Files file>, <Location URL> in ascending order of authority. <Location> can overwrite others.

• dir, file, URL can specify using wildcards and full regular expressions preceded by “~”

Page 12: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 12

List of Directives • User, Group: specify user and group that httpd runs on.• ServerName: hostname of server (for redirection URL) • ResourceConfig, AccessConfig: for reading additional related

directives. Can be disabled by /dev/null as value• Port: specify the port httpd run on• ServerAdmin:email addr. for browser to do automatic replies.

• DocumentRoot:• TransferLog, ErrorLog, PidFile: where access,error logs,

httpd.pid should be located. Can be file or pipe “|rotatelogs”The file is relative to the server root directory(specified in httpd -d <server root> or /usr/local/etc/httpd)

Page 13: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 13

Directives• KeepAlive [on|off](on): keep connection alive for n requests before

terminate provided they come in before timeout. n is defined in MaxKeepAliveRequests <n>(100) directive

• KeepAliveTimeout <n>(15): wait for the next request for n seconds before terminate the connections.

• Timeout <n>(300): max. time in sec for a block data.• HostNameLookups [on|off|double](off): do reverse DNS lookup for logging

the domain name of the request.• MaxClients <n>(256): the limit of # of simultaneous requests (hence the #

of child processes).• MaxRequestsPerChild <n>(0): Spare(child) server dies after <n>

requests, avoid mem leak. 0 mean infinite requests. • Min/MaxSpareServers <n>(5/10): # of Idle child servers• StartServers <n>(5): sets the number of child server processes created on

startup.

Page 14: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 14

Homework#3 Exercise 1:Site.toddle and Site.simple

• “cp -r /mpc/home/www/sites /mpc/home/<login>“• Edit the httpd.conf in conf directory

DocumentRoot /usr/www/site.simple/htdocs DocumentRoot /mpc/home/<login>/sites/site.simple/htdocs Port 8<last 3 digits of your SS#>TransferLog logs/access_log

• Edit go shell script “httpd -d /mpc/home/<login>/sites/site.<name> [-X]“go in the site.simple does not have –X.

• go will start the web server. Control-c will terminate it.• Use browser to visit the site a few times. Remember to specify the

port # in url. For IE browser, type http://bilbo.uccs.edu:<portno>/ or http://frodo.uccs.edu:<portno>/ depending which machine

• Check the access_log file. Keep them as record

Page 15: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 15

Homework#3 Exercise 1User webuser

Group webgroup

ServerName bilbo.uccs.edu or frodo.uccs.edu

DocumentRoot /mpc/home/<login>/sites/site.toddle/htdocs

Port 8<last 3 digits of your SS#>

TransferLog logs/access_log

Page 16: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 16

Site.twocopy

• Create two web servers: one serves customers; one for sales. There are two directories in site.twocopy.

• In customers/conf/httpd.conf,replace www.butterthlies.com with bilbo.uccs.eduadd Port 8<last 3 digits of SS#>

• Here BindAddress is used to specify the reception of request from specific IP address (domain name) by this web server. BindAddress bilbo.uccs.edu

• In sales/conf/httpd.confreplace sales.butterthlies.com with b2b.uccs.eduReplace Listen sales.butterthlies.com:80 withListen b2b.uccs.edu:8<last 3 digits of SS#>

• httpd -d /mpc/home/<login>/sites/site.twocopy/customers -X• httpd -d /mpc/home/<login>/sites/site.twocopy/sales -X

Page 17: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 17

Web Hosting

• Named-based vs. IP-based Virtual Host (VH)HOST: <name> a unique IP address for each VHon metaheader different to support a lot of VHsold browsers notsupport this

• Use <VirtualHost hostname[:port]> block directives• Specify ServerAdmin, DocumentRoot, ServerName,

ErrorLog, TransferLog for individual VH• Be aware that UNIX File Limits on # of file

descriptors. (default 64) only support 32 VHs?• You may want to increase # of child servers.

Page 18: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 18

Site.Virtual/Name-based• cd /mpc/home/<login>/sites/site.virtual/Name-based• edit the httpd.conf in conf directory:• NameVirtualHost 192.168.123.2

NameVirtualHost 128.198.192.182Port 8<last 3 digits of SS#>

• <VirtualHost www.butterthlies.com> <VirtualHost bilbo.uccs.edu:portno>Here portno is 8<last 3 digits of your SS#>

• ServerAdmin [email protected] ServerAdmin <login>@cs.uccs.edu

• /usr/www /mpc/home/<login>/sites/• <VirtualHost sales.butterthlies.com>

<VirtualHost sales-bilbo.uccs.edu:portno>• Go to start virtual hositng.

Page 19: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 19

Site.Virtual/IP-based• cd /mpc/home/<login>/sites/site.virtual/IP-based• edit the httpd.conf in conf directory:• Add Port 8<last 3 digits of SS#>

right after Group webgroup• <VirtualHost 192.168.123.2>

<VirtualHost 128.198.192.182:portno>Here portno is 8<last 3 digits of your SS#>

• ServerName bilbo.uccs.edu• ServerAdmin [email protected]

ServerAdmin <login>@cs.uccs.edu• /usr/www /mpc/home/<login>/sites/• <VirtualHost 192.168.123.3>

<VirtualHost 128.198.192.172:portno>• ServerName b2b.uccs.edu

Page 20: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 20

Site.Virtual/Mixed-based

• We can mix Name-based with IP-based virtual hosting.• Change “IP-based” to “Mixed-based”. An error in config file.

NameVirtualHost 128.198.192.182:8888

Port 8888

<VirtualHost bilbo.csnet.uccs.edu:8888>

DocumentRoot /mpc/home/guest/sites/site.virtual/htdocs/customers

<VirtualHost salesbilbo.csnet.uccs.edu:8888>

DocumentRoot /mpc/home/guest/sites/site.virtual/htdocs/salesmen

<VirtualHost 128.198.192.172:8888>

DocumentRoot /mpc/home/guest/sites/site.virtual/htdocs/salesmen

Page 21: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 21

Port-based Virtual Hosting

• Can use one IP address to test many sites.• Change IP-based to Port-based. An error in config file.• Different ports map to different sites.

User webuser

Group webgroup

Listen 7888

Listen 8888

<VirtualHost 128.198.192.182:7888>

DocumentRoot /mpc/home/guest/sites/site.virtual/htdocs/customers

<VirtualHost 128.198.192.182:8888>

DocumentRoot /mpc/home/guest/sites/site.virtual/htdocs/salesmen

Page 22: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 22

Bonus Exercise #1

• After copying the site.virtual to the nfs mount dir and executing the httpd, the access_log and error_log files are empty.

• When use the directory mounted on local disk, there are no problem.

• See the bonus exercise on http://owl/~cs401/bonus.html

• Try to explain why this happens.• A good answer gets 1 point count towards final

grade.

Page 23: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 23

Homework #3 Exercise 2

• Run site.virtual/Name-based, site.virtual/IP-based, and site.twocopy according to the textbook and verify the results.

• Keep the access_log and error_log as records.• Send me email when you finish both exercises.

Page 24: Apache web server installation/configuration, Virtual Hosting

04/12/23 C. Edward Chow

CS401

Page 24

Homework #3: Problem 3

• Explain why it is possible not to require a new IP address to host a customer’s web site, even though it has a unique domain name.