[root@zzu ~]# cd /mnt/cdrom/Server/    
[root@zzu Server]# ll http*    
-r--r--r-- 86 root root 1266575 Jul 28  2009 httpd-2.2.3-31.el5.i386.rpm    
-r--r--r-- 99 root root  150002 Jul 28  2009 httpd-devel-2.2.3-31.el5.i386.rpm 包含头文件和库文件      
-r--r--r-- 86 root root  830924 Jul 28  2009 httpd-manual-2.2.3-31.el5.i386.rpm 帮助书册

[root@zzu Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm

[root@zzu Server]# rpm -ivh httpd-devel-2.2.3-31.el5.i386.rpm

[root@zzu Server]# rpm -ivh httpd-manual-2.2.3-31.el5.i386.rpm

[root@zzu Server]# cd /var/www/html/    
[root@zzu html]# vim index.html

1:http的与派生机制(1个父进程和8个子进程)

[root@zzu html]# ps aux|grep httpd    
root      2568  0.0  0.2   7496  2704 pts/2    S+   00:34   0:00 vim conf/httpd.conf    
root      3603  0.0  0.2  10576  2940 ?        Ss   02:15   0:00 /usr/sbin/httpd    
apache    3604  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd    
apache    3605  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd    
apache    3606  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd    
apache    3607  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd    
apache    3608  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd    
apache    3610  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd    
apache    3611  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd    
apache    3612  0.0  0.2  10576  2120 ?        S    02:15   0:00 /usr/sbin/httpd

[root@zzu httpd]# cat run/httpd.pid 父进程的pid      
3603

[root@zzu ~]# cat /etc/httpd/conf.d/welcome.conf  www服务器的测试页面

2:目录安全性和符号链接的跟踪

[root@zzu ~]# vim /etc/httpd/conf/httpd.conf

306 alias /qq   "/var/www/html"

307 <Directory "/var/www/html">

321     Options Indexes FollowSymLinks

336 </Directory>

[root@zzu ~]# mkdir /qq

[root@zzu ~]# cd /var/www/html/

[root@zzu html]# touch f1

[root@zzu html]# ln -s /etc/passwd ln1

[root@zzu ~]# service httpd restart    
Stopping httpd:                                            [  OK  ]    
Starting httpd:                                            [  OK  ]

linux下www服务器技术总结_color

linux下www服务器技术总结_color_02

linux下www服务器技术总结_2009_03

3:身份验证

[root@zzu html]# vim /etc/httpd/conf/httpd.conf

307 <Directory "/var/www/html">

327     AllowOverride all

336 </Directory>

[root@zzu ~]# cd /var/www/html/

[root@zzu html]# vim index.html    
hello!!!!!!!!!!!!!    
[root@zzu html]# vim .htaccess 创建目录访问的控制文件      
authuserfile /var/www/html/.htpasswd 账号文件的位置      
authtype basic    
authname  "please input your name and passwd"    
require valid-user

[root@zzu html]# htpasswd -c .htpasswd user1  产生账号user1      
New password:    
Re-type new password:    
Adding password for user user1    
[root@zzu html]# htpasswd .htpasswd user2   产生账号user2
New password:    
Re-type new password:    
Adding password for user user2

[root@zzu html]# service httpd restart

linux下www服务器技术总结_160_04

linux下www服务器技术总结_160_05

4:个人站点的发布

349 <IfModule mod_userdir.c>    
355     # UserDir disable 注释掉该行      
362     UserDir public_html 启用该行      
364 </IfModule>

370 <Directory /home/*/public_html>    
372     Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec 注释掉该行
381 </Directory>

[root@zzu html]# useradd user1    
[root@zzu html]# echo "123"|passwd --stdin user1    
Changing password for user user1.    
passwd: all authentication tokens updated successfully

增加用户user1

[root@zzu html]# useradd user1    
[root@zzu html]# echo "123"|passwd --stdin user1    
Changing password for user user1.    
passwd: all authentication tokens updated successfully.    
[root@zzu html]# su - user1    
[user1@zzu ~]$ pwd    
/home/user1    
[user1@zzu ~]$ mkdir public_html    
[user1@zzu ~]$ ll    
total 4    
drwxrwxr-x 2 user1 user1 4096 Feb  8 03:14 public_html    
[user1@zzu ~]$ vim index.html

this is user1' home!!!!!!!!!!!!!!!!

[root@zzu ~]# service httpd restart

linux下www服务器技术总结_color_06

[root@zzu ~]# su - user1    
[user1@zzu ~]$ pwd    
/home/user1    
[user1@zzu ~]$ cd ..    
[user1@zzu home]$ ll    
total 12    
drwx------ 4 user1   user1   4096 Feb  8 03:23 user1 user1的目录other用户没有可读的权限      
[user1@zzu home]$ chmod o+rx user1/    
[user1@zzu home]$ ll    
total 12    
drwx---r-x 4 user1   user1   4096 Feb  8 03:23 user1

[root@zzu ~]# service httpd restart

linux下www服务器技术总结_color_07

改进:

370 alias /user1 "/home/*/public_html"    
371 <Directory /home/*/public_html>    
373     Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec    
382 </Directory>

linux下www服务器技术总结_color_08

5:基于ip地址的来源控制

307 <Directory "/var/www/html">

332     Order allow,deny  
333     Allow from 192.168.1.5  只允许192.168.1.5访问

336 </Directory>

linux下www服务器技术总结_2009_09

linux下www服务器技术总结_color_10

linux下www服务器技术总结_color_11

linux下www服务器技术总结_color_12

307 <Directory "/var/www/html">

332     Order allow,deny  
333     Allow from 192.168.1.0/24  
334     deny from 192.168.1.5  

336 </Directory>

linux下www服务器技术总结_color_11

linux下www服务器技术总结_color_10

linux下www服务器技术总结_2009_09

linux下www服务器技术总结_color_12

linux下www服务器技术总结_160_17

linux下www服务器技术总结_color_18

6:虚拟目录

alias /qq   "/var/www/html"

307 <Directory "/var/www/html">

336 </Directory>

linux下www服务器技术总结_2009_19

7:基于ip地址的虚拟主机

[root@zzu html]# ifconfig eth0:0 192.168.1.101    
[root@zzu html]# ifconfig eth0:1 192.168.1.102

[root@zzu html]# ifconfig    
eth0      Link encap:Ethernet  HWaddr 00:0C:29:4B:61:16  
         inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:4B:61:16  
         inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:4B:61:16  
         inet addr:192.168.1.102  Bcast:192.168.1.255  Mask:255.255.255.0

[root@zzu ~]# cd /var/www    
[root@zzu www]# mkdir tec mkt

tec!!!!!!!!!!!!!!!!!

[root@zzu www]# vim mkt/index.html    
mkt!!!!!!!!!!!!!!!!

[root@zzu www]# vim /etc/httpd/conf/httpd.conf

<VirtualHost 192.168.1.100:80>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/html    
   ServerName www.abc.com    
   ErrorLog logs/error_log_www    
   CustomLog logs/access_log_www common    
</VirtualHost>    
<VirtualHost 192.168.1.101:80>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/tec    
   ServerName tec.abc.com    
   ErrorLog logs/error_log_tec    
   CustomLog logs/access_log_tec common    
</VirtualHost>    
<VirtualHost 192.168.1.102:80>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/mkt    
   ServerName mkt.abc.com    
   ErrorLog logs/error_log_www    
   CustomLog logs/access_log_www common    
</VirtualHost>

[root@zzu www]# service httpd restart    
Stopping httpd:                                            [  OK  ]    
Starting httpd:                                             [  OK  ]

C:\WINDOWS\system32\drivers\etc\hosts 修改该文件

192.168.1.100 www.abc.com    
192.168.1.101 tec.abc.com    
192.168.1.102 mkt.abc.com

linux下www服务器技术总结_color_20

linux下www服务器技术总结_160_21

linux下www服务器技术总结_2009_22

8:基于端口的虚拟主机

C:\WINDOWS\system32\drivers\etc\hosts 修改该文件

192.168.1.100 www.abc.com

[root@zzu www]# vim /etc/httpd/conf/httpd.conf    
listen 80

listen 800    
listen 8000

<VirtualHost 192.168.1.100:80>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/html    
   ServerName www.abc.com    
   ErrorLog logs/error_log_www    
   CustomLog logs/access_log_www common    
</VirtualHost>    
<VirtualHost 192.168.1.100:800>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/tec    
   ServerName tec.abc.com    
   ErrorLog logs/error_log_tec    
   CustomLog logs/access_log_tec common    
</VirtualHost>    
<VirtualHost 192.168.1.100:8000>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/mkt    
   ServerName mkt.abc.com    
   ErrorLog logs/error_log_www    
   CustomLog logs/access_log_www common    
</VirtualHost>

linux下www服务器技术总结_2009_23

linux下www服务器技术总结_2009_24  

linux下www服务器技术总结_color_25

9:基于主机头的虚拟主机

C:\WINDOWS\system32\drivers\etc\hosts 修改该文件

192.168.1.100 www.abc.com    
192.168.1.100 tec.abc.com    
192.168.1.100 mkt.abc.com

[root@zzu www]# vim /etc/httpd/conf/httpd.conf

NameVirtualHost 192.168.1.100:80

<VirtualHost 192.168.1.100:80>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/html    
   ServerName www.abc.com    
   ErrorLog logs/error_log_www    
   CustomLog logs/access_log_www common    
</VirtualHost>    
<VirtualHost 192.168.1.100:80>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/tec    
   ServerName tec.abc.com    
   ErrorLog logs/error_log_tec    
   CustomLog logs/access_log_tec common    
</VirtualHost>    
<VirtualHost 192.168.1.100:80>    
   ServerAdmin root@zzu.com    
   DocumentRoot /var/www/mkt    
   ServerName mkt.abc.com    
   ErrorLog logs/error_log_mkt

  CustomLog logs/access_log_mkt common    
</VirtualHost>

linux下www服务器技术总结_2009_26

linux下www服务器技术总结_color_27

linux下www服务器技术总结_160_28

10:ab压力测试工具

模拟同时在线1000个用户请求10000次

[root@zzu ~]# ab -c 1000 -n 10000 http://127.0.0.1/index.html
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0    
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)  
Completed 1000 requests    
Completed 2000 requests    
Completed 3000 requests    
Completed 4000 requests    
Completed 5000 requests    
Completed 6000 requests    
Completed 7000 requests    
Completed 8000 requests    
Completed 9000 requests    
Finished 10000 requests

Server Software:        Apache/2.2.3  
Server Hostname:        127.0.0.1    
Server Port:            80

Document Path:          /index.html  
Document Length:        19 bytes

Concurrency Level:      1000  
Time taken for tests:   8.446858 seconds 测试耗时8s    
Complete requests:      10000    
Failed requests:        0    
Write errors:           0    
Total transferred:      2820000 bytes    
HTML transferred:       190000 bytes    
Requests per second:    1183.87 [#/sec] (mean)    
Time per request:       844.686 [ms] (mean)    
Time per request:       0.845 [ms] (mean, across all concurrent requests)平均每次请求不到一秒钟    
Transfer rate:          325.92 [Kbytes/sec] received

Connection Times (ms)  
             min  mean[+/-sd] median   max    
Connect:        0   74 487.1      1    6051    
Processing:     0  504 1381.3     57    6135    
Waiting:        0  502 1381.7     55    6135    
Total:         31  579 1532.0     58    6809

Percentage of the requests served within a certain time (ms)  
 50%     58    
 66%     73    
 75%     83    
 80%    101    
 90%   1835   90%的请求在1s左右正常    
 95%   5785    
 98%   6516    
 99%   6620    
100%   6809 (longest request)    
[root@zzu ~]#

欢迎加入郑州阳仔的网络工程师自由交流群--132444800(请注明自己的身份,就说是51cto的博友)