CO 246 - Web Server Administration and Security By: Szymon Machajewski
CO 246 - Web Server Administration and Security By: Szymon Machajewski Online: < http://cnx.org/content/col11452/1.1/ > C O N N E X I O N S Rice University, Houston, Texas
This selection and arrangement of content as a collection is copyrighted by Szymon Machajewski. It is licensed under the Creative Commons Attribution 3.0 license (http://creativecommons.org/licenses/by/3.0/). Collection structure revised: November 1, 2012 PDF generated: November 1, 2012 For copyright and attribution information for the modules contained in this collection, see p. 10.
Table of Contents 1 Apache httpd Web Server - installation from source code.................................... 1 2 Apache httpd Web Server - basic conguration................................................ 3 3 Apache httpd Web Server - logs lab............................................................ 7 Index..................................................................................................9 Attributions......................................................................................... 10
iv
Chapter 1 Apache httpd Web Server - installation from source code1 Start the lab by booting your Knoppix system. You can simply put it in a CDROM and restart the computer or you can use a VMware virtual machine. Once you see the Knoppix desktop simply click on the Console icon at the bottom of the screen. You can stay logged in as the knoppix user. Open the Terminal window for the lab and type in commands into the Terminal. Exercise 1.1: Step 1 (Solution on p. 2.) 1. Download Apache sources. You can download the source code directly from the Apache Foundation (http://httpd.apache.org/), or you can use the local GRCC repository. In the classroom the local download will be much faster. Exercise 1.2: Step 2 (Solution on p. 2.) 2. Decompress and extract the source les. Exercise 1.3: Step 3 (Solution on p. 2.) 3. Change directory to the source directory. Exercise 1.4: Step 4 (Solution on p. 2.) 4. Clean source tree. If you are compiling for the rst time you can skip this step. Executing this step will not change any conguration. Exercise 1.5: Step 5 (Solution on p. 2.) 5. Congure the sources. Exercise 1.6: Step 6 (Solution on p. 2.) 6. Compile source code Exercise 1.7: Step 7 (Solution on p. 2.) 7. Install source code Exercise 1.8: Step 8 (Solution on p. 2.) 8. Start Apache server Exercise 1.9: Step 9 (Solution on p. 2.) 9. Test to check if Apache is running Exercise 1.10: Step 10 (Solution on p. 2.) 10. Test with terminal commands Exercise 1.11: Step 11 (Solution on p. 2.) 11. To start the entire process over run the following command to delete your apache system. ATTENTION! The rm -rf command will uninstall or delete the Apache Web Server. 1 This content is available online at <http://cnx.org/content/m45031/1.2/>. 1
2 CHAPTER 1. Solutions to Exercises in Chapter 1 Solution to Exercise 1.1 (p. 1) wget http://raider.grcc.edu/ smachaje/co246/httpd-2.0.59.tar.gz Solution to Exercise 1.2 (p. 1) tar -xzvf httpd-2.0.59.tar.gz Solution to Exercise 1.3 (p. 1) cd httpd-2.0.59 Solution to Exercise 1.4 (p. 1) make clean Solution to Exercise 1.5 (p. 1)./congure prex=/home/knoppix/apache with-port=8080 Solution to Exercise 1.6 (p. 1) make Solution to Exercise 1.7 (p. 1) make install Solution to Exercise 1.8 (p. 1) cd /home/knoppix/apache bin/apachectl start Solution to Exercise 1.9 (p. 1) Open the browser and navigate to http://localhost:8080/ Solution to Exercise 1.10 (p. 1) netstat -ln grep 8080 ps -ef grep httpd Solution to Exercise 1.11 (p. 1) killall httpd rm -rf /home/knoppix/apache APACHE HTTPD WEB SERVER - INSTALLATION FROM SOURCE CODE
Chapter 2 Apache httpd Web Server - basic conguration 1 Exercise 2.1: Conguration le (Solution on p. 6.) Open and review the main conguration le for our Apache installation. note: You can use any text editor. The solutions will use leafpad from Knoppix livecd. Other editors on the Knoppix CD include: vi, xedit, nano, pico. Exercise 2.2 (Solution on p. 6.) First let's x the error message which comes up every time we start apache. The message says: httpd: Could not determine the server's fully qualied domain name, using 127.0.0.1 for Server- Name Exercise 2.3 (Solution on p. 6.) Find the following directives and change their values in the conguration le. For new conguration to take eect you have to save the conguration le and restart apache. Above at the end of step 1 you will nd the commands to restart apache. Find the following directives and change their values: A) Change ServerAdmin to your email address. Before change: ServerAdmin you@example.com Change to: ServerAdmin myemail@host.com B) Add index.php to the default pages. Before change: DirectoryIndex index.html index.html.var Change to: DirectoryIndex index.html index.html.var index.php C) Change the detail of logging. Before change: LogLevel warn 1 This content is available online at <http://cnx.org/content/m45045/1.1/>. 3
4 CHAPTER 2. APACHE HTTPD WEB SERVER - BASIC CONFIGURATION Change to: LogLevel error D) Change Server Signature: ServerSignature Email E) Change the server HTTP Header information: ServerTokens Prod F) Change the user and group which Apache runs as: User knoppix Group knoppix Exercise 2.4: Virtual Hosts (Solution on p. 6.) 1. Setup site host names Edit /etc/hosts. You need to edit the lines as the root user. In the terminal type in: su leafpad /etc/hosts add the following lines: 127.0.0.1 www.co246.com 127.0.0.1 go.co246.com 127.0.0.1 student.co246.com Exit the shell as root so you are logged in as Knoppix. Test the host names by visiting the urls in a browser. Remember to start the Apache server on port 8080. 2. Congure Apache to recognize Virtual Hosts Edit httpd.conf and add the following sections: # Use name-based virtual hosting. # NameVirtualHost *:8080 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The rst VirtualHost section is used for requests without a known
5 # server name. # <VirtualHost *:8080> ServerAdmin student@grcc.edu DocumentRoot /home/knoppix/go_co246_htdocs/ ServerName go.co246.com ErrorLog logs/go_co246_error_log CustomLog logs/go_co246_access_log common </VirtualHost> <VirtualHost *:8080> ServerAdmin student@grcc.edu DocumentRoot /home/knoppix/student_co246_htdocs/ ServerName student.co246.com ErrorLog logs/student_co246_error_log CustomLog logs/student_co246_access_log common <VirtualHost> <VirtualHost *:8080> ServerAdmin student@grcc.edu DocumentRoot /home/knoppix/www_co246_htdocs/ ServerName www.co246.com ErrorLog logs/www_co246_error_log CustomLog logs/www_co246_access_log common <VirtualHost> 3. Create each DocumentRoot directory with a sample index.html page. For example create: mkdir /home/knoppix/www_co246_htdocs cd /home/knoppix/www_co246_htdocs echo ``This is www_co246 site'' > index.html mkdir /home/knoppix/go_co246_htdocs cd /home/knoppix/go_co246_htdocs echo ``This is go_co246 site'' > index.html mkdir /home/knoppix/student_co246_htdocs cd /home/knoppix/student_co246_htdocs echo ``This is student_co246 site'' > index.html
6 CHAPTER 2. APACHE HTTPD WEB SERVER - BASIC CONFIGURATION Solutions to Exercises in Chapter 2 Solution to Exercise 2.1 (p. 3) leafpad /home/knoppix/apache/conf/httpd.conf Solution to Exercise 2.2 (p. 3) To x it edit the httpd.conf le ( leafpad /home/knoppix/apache/conf/httpd.conf ) and change the Server- Name directive to be: ServerName localhost:8080 The directive before the change: #ServerName www.example.com:80 The directive after change: ServerName localhost:8080 Save the le and restart apache: cd /home/knoppix/apache bin/apachectl stop bin/apachectl start or /home/knoppix/apache/bin/apachectl restart Now you shouldn't see an error message when Apache starts. Solution to Exercise 2.3 (p. 3) Test the excercise by visiting the following urls on the your server: http://localhost:8080/manual/ http://localhost:8080/icons/ (note at the bottom of the icon les the localhost link. It should have your email address as the destination url) http://localhost:8080/cgi-bin/test-cgi (if you get an error here that's ne. to x the error run: chmod 777 /home/knoppix/apache/cgi-bin/* view the HTTP HEADERS of your server: wget --spider -S http://localhost:8080/ Solution to Exercise 2.4 (p. 4) Open a browser and navigate to http://www.co246.com, http://go.co246.com, http://student.co246.com
Chapter 3 Apache httpd Web Server - logs lab 1 Exercise 3.1 (Solution on p. 8.) 1. Enable extended server status in httpd.conf le. You can nd instructions in the Apache manual http://httpd.apache.org/docs/2.0/mod/mod_status.html 2. Generate Apache activity: apache/bin/ab -n 200 -c 1 http://localhost:8080/ apache/bin/ab -n 200000 -c 1000 http://localhost:8080/ 3. View the server status at: http://localhost:8080/server-status 4. Monitor log les at apache/logs/ tail -f apache/logs/access_log 5. Generate error logs: apache/bin/ab -n 200 -c 1 http://localhost:8080/`date +%s` for ((i=1;i<5;i+=1)); do apache/bin/ab -n 2 -c 1 http://localhost:8080/`date +%s`; sleep 2; done; 1 This content is available online at <http://cnx.org/content/m45046/1.1/>. 7
8 CHAPTER 3. APACHE HTTPD WEB SERVER - LOGS LAB Solutions to Exercises in Chapter 3 Solution to Exercise 3.1 (p. 7) Monitor log les at apache/logs/ cat /home/knoppix/apache/logs/access_log
INDEX 9 Index of Keywords and Terms Keywords are listed by the section with that keyword (page numbers are in parentheses). Keywords do not necessarily appear in the text of the page. They are merely associated with that section. Ex. apples, Ÿ 1.1 (1) Terms are referenced by the page they appear on. Ex. apples, 1 A apache, Ÿ 1(1), Ÿ 2(3), Ÿ 3(7) C compiling, Ÿ 1(1) computer science, Ÿ 1(1) conguration, Ÿ 2(3) H httpd, Ÿ 1(1), Ÿ 2(3), Ÿ 3(7) httpd.conf, Ÿ 2(3) L log les, Ÿ 3(7) logs, Ÿ 3(7) S security, Ÿ 1(1) source code, Ÿ 1(1) T technology, Ÿ 1(1) W web server, Ÿ 1(1)
10 ATTRIBUTIONS Attributions Collection: CO 246 - Web Server Administration and Security Edited by: Szymon Machajewski URL: http://cnx.org/content/col11452/1.1/ License: http://creativecommons.org/licenses/by/3.0/ Module: "Apache httpd Web Server - installation from source code" By: Szymon Machajewski URL: http://cnx.org/content/m45031/1.2/ Pages: 1-2 Copyright: Szymon Machajewski License: http://creativecommons.org/licenses/by/3.0/ Module: "Apache httpd Web Server - basic conguration" By: Szymon Machajewski URL: http://cnx.org/content/m45045/1.1/ Pages: 3-6 Copyright: Szymon Machajewski License: http://creativecommons.org/licenses/by/3.0/ Module: "Apache httpd Web Server - logs lab" By: Szymon Machajewski URL: http://cnx.org/content/m45046/1.1/ Pages: 7-8 Copyright: Szymon Machajewski License: http://creativecommons.org/licenses/by/3.0/
About Connexions Since 1999, Connexions has been pioneering a global system where anyone can create course materials and make them fully accessible and easily reusable free of charge. We are a Web-based authoring, teaching and learning environment open to anyone interested in education, including students, teachers, professors and lifelong learners. We connect ideas and facilitate educational communities. Connexions's modular, interactive courses are in use worldwide by universities, community colleges, K-12 schools, distance learners, and lifelong learners. Connexions materials are in many languages, including English, Spanish, Chinese, Japanese, Italian, Vietnamese, French, Portuguese, and Thai. Connexions is part of an exciting new information distribution system that allows for Print on Demand Books. Connexions has partnered with innovative on-demand publisher QOOP to accelerate the delivery of printed course materials and textbooks into classrooms worldwide at lower prices than traditional academic publishers.