Apache

#   yum install httpd   httpd-manual -y
# rpm -ql httpd |less
# service httpd start
# firefox &  
http://192.168.3.2/

# chkconfig httpd on       //让web服务随系统启动启动
# cd /var/www/html
# echo "大家好,欢迎来到我的空间" > index.html
# firefox &  
http://192.168.3.2/

# cd /etc/httpd/conf

把vbird  vbird-server 传到  /var/www/html目录下
# vim httpd.conf
337 <directory "/var/www/html/vbird">
338     Options  Indexes  FollowSymLinks
339     AllowOverride  none
340     Order allow,deny
341     Allow from all
342 </directory>

398 DirectoryIndex index.html index.html.var  linux_basic.php.htm

# service httpd restart
# firefox &  
http://192.168.3.2/vbird/
------------------------
支持验证
# vim /etc/httpd/conf/httpd.conf

 337 <directory "/var/www/html/vbird">
 338     Options  Indexes  FollowSymLinks
 339     AllowOverride  all
 340     authname "vbird"
 341     authtype basic
 342     authuserfile  "/var/www/html/vbird/.htpasswd"
 343     require  valid-user
 344     Order allow,deny
 345     Allow from all
 346 </directory>


[root@teacher conf]# cd /var/www/html/vbird
[root@teacher vbird]# htpasswd  -c .htpasswd u1
New password: 
Re-type new password: 

[root@teacher vbird]# htpasswd .htpasswd u2
New password: 
Re-type new password: 

# service httpd restart
--------------------------------
访问控制

# vim /etc/httpd/conf/httpd.conf

<directory "/var/www/html/vbird">
    Options  Indexes  FollowSymLinks
    AllowOverride  all
    authname "vbird"
    authtype basic
    authuserfile  "/var/www/html/vbird/.htpasswd"
    require  valid-user
    Order allow,deny
    Allow from  192.168.3.20    //白名单,只允许192.168.3.20访问
</directory>

# service httpd restart

-----------------------------

# vim /etc/httpd/conf/httpd.conf

<directory "/var/www/html/vbird">
    Options  Indexes  FollowSymLinks
    AllowOverride  all
    authname "vbird"
    authtype basic
    authuserfile  "/var/www/html/vbird/.htpasswd"
    require  valid-user
    Order deny,allow
    deny from  192.168.3.20
</directory>

# service httpd restart

-----------------------
虚拟主机

基于域名

# vim /etc/httpd/conf/httpd.conf

 984 NameVirtualHost *:80


1005 <VirtualHost *:80>
1006     ServerAdmin admin@google.com
1007     DocumentRoot /var/www/html/google
1008     ServerName www.google.com
1009     ErrorLog logs/google.com-error_log
1010     CustomLog logs/google.com-access_log common
1011 </VirtualHost>
1012 
1013 <VirtualHost *:80>
1014     ServerAdmin admin@baidu.com
1015     DocumentRoot /var/www/html/baidu
1016     ServerName www.baidu.com
1017     ErrorLog logs/baidu.com-error_log
1018     CustomLog logs/baidu.com-access_log common
1019 </VirtualHost>

//域名解析
# vim /etc/hosts
192.168.3.2   www.google.com
192.168.3.2   www.baidu.com

//创建网页存放目录
# mkdir /var/www/html/google
# mkdir /var/www/html/baidu

//创建默认首页
[root@teacher vbird]# cd /var/www/html/google/
[root@teacher google]# echo "欢迎来到google!" > index.html

# cd /var/www/html/baidu
# echo "欢迎来到baidu!" > index.html

//服务重启
# service httpd restart

# firefox http://www.google.com
# firefox http://www.baidu.com

--------------------------------
基于ip地址

# cd /etc/sysconfig/network-scripts/
//在一块网卡绑定多个ip地址
# cp -p ifcfg-eth0  ifcfg-eth0:0
# vim ifcfg-eth0:0

DEVICE=eth0:0
BOOTPROTO=none
IPADDR=192.168.3.3
ONBOOT=yes

# service network restart

# vim /etc/httpd/conf/httpd.conf 

 984 #NameVirtualHost *:80

1005 <VirtualHost 192.168.3.2:80>
1006     ServerAdmin admin@google.com
1007     DocumentRoot /var/www/html/google
1008     ServerName www.google.com
1009     ErrorLog logs/google.com-error_log
1010     CustomLog logs/google.com-access_log common
1011 </VirtualHost>
1012 
1013 <VirtualHost 192.168.3.3:80>
1014     ServerAdmin admin@baidu.com
1015     DocumentRoot /var/www/html/baidu
1016     ServerName www.baidu.com
1017     ErrorLog logs/baidu.com-error_log
1018     CustomLog logs/baidu.com-access_log common
1019 </VirtualHost>

# vim /etc/hosts

192.168.3.2   www.google.com
192.168.3.3   www.baidu.com

# service httpd restart

[root@teacher network-scripts]# firefox http://www.google.com
[root@teacher network-scripts]# firefox http://www.baidu.com

-------------------
基于端口

# vim /etc/httpd/conf/httpd.conf 

 134 Listen 80
 135 Listen 8080

1007 <VirtualHost 192.168.3.2:80>
1008     ServerAdmin admin@google.com
1009     DocumentRoot /var/www/html/google
1010     ServerName www.google.com
1011     ErrorLog logs/google.com-error_log
1012     CustomLog logs/google.com-access_log common
1013 </VirtualHost>
1014 
1015 <VirtualHost 192.168.3.2:8080>
1016     ServerAdmin admin@baidu.com
1017     DocumentRoot /var/www/html/baidu
1018     ServerName www.baidu.com
1019     ErrorLog logs/baidu.com-error_log
1020     CustomLog logs/baidu.com-access_log common
1021 </VirtualHost>

# vim /etc/hosts

192.168.3.2   www.google.com
192.168.3.2   www.baidu.com

# service httpd restart

[root@teacher /]# firefox http://www.google.com
[root@teacher /]# firefox http://www.baidu.com:8080

---------------------------
错误消息提示

把虚拟就设置取消掉,服务重启
# service httpd restart
# vim /etc/httpd/conf/httpd.conf 

<directory "/var/www/html/test">
    Options  Indexes  FollowSymLinks
    AllowOverride  none
    errordocument  403  /error/403.html
    errordocument  404  /error/404.html
    Order allow,deny
    allow from all
</directory>

# mkdir /var/www/html/test
# echo "hello" > index.html
[root@teacher test]# ls -l index.html 
-rw-r--r-- 1 root root 6 Aug 15 15:20 index.html
[root@teacher test]# chmod 640  index.html

# cd /var/www/error/
[root@teacher error]# echo "网站维护中"  > 403.html
[root@teacher error]# echo "您找的页面不存在"  > 404.html

# firefox http://192.168.3.2/test
# firefox http://192.168.3.2/test/slidfhsfg
-----------------------------
CGI

# vim /etc/httpd/conf/httpd.conf 

# cd /var/www/cgi-bin/
[root@teacher cgi-bin]# ls
[root@teacher cgi-bin]# vim t.cgi

#!/bin/bash
echo "content-type:text/html"
echo ""
echo "<html>"
echo "<h1>this is cgi-bin!</center></h1>"
echo "<hr>"
echo "</html>"

ls -l /
cat /etc/passwd

# chmod o+x t.cgi
# firefox http://192.168.3.2/cgi-bin/t.cgi

----------------------------------
# ab -n 1000 -c 100 http://192.168.3.2

-----------------------
要求个人证书的网页服务器

# yum install mod_ssl -y

# mkdir -pv /etc/ssl/private
创建服务器私钥
# openssl genrsa -des3 -out /etc/ssl/private/server.key 1024   
创建证书签名请求
# openssl req -new -key /etc/ssl/private/server.key -out  /etc/ssl/private/server.csr
创建自签名证书
# openssl x509 -req -days 365 -in /etc/ssl/private/server.csr -signkey  /etc/ssl/private/server.key -out /etc/ssl/server.crt

# mkdir /etc/ssl/client
创建客户端私钥
# openssl genrsa -des3 -out /etc/ssl/client/client.key 1024
创建证书签名请求
# openssl -req -new -key /etc/ssl/client/client.key  -out /etc/ssl/client/client.csr
创建客户端自签名证书
# openssl x509 -req -days 365 -in /etc/ssl/client/client.csr -signkey /etc/ssl/client/client.key -out /etc/ssl/client/client.crt
导出windows证书
# openssl pkcs12 -export -clcerts -in /etc/ssl/client/client.crt  -inkey  /etc/ssl/client/client.key -out /etc/ssl/client/client.p12

# cd /etc/ssl/client/
[root@teacher client]# ls
client.crt  client.csr  client.key  client.p12
[root@teacher client]# cp -p client.p12  /var/www/html

在windows下用ie浏览器下载证书  http://192.168.3.2/client.p12

[root@teacher client]# cd /etc/httpd/conf.d
[root@teacher conf.d]# vim ssl.conf 

 18 #Listen 443

113 SSLCertificateFile /etc/ssl/server.crt

SSLCertificateKeyFile /etc/ssl/private/server.key


136 SSLCACertificateFile /etc/ssl/client/client.crt

143 SSLVerifyClient require

# vim /etc/httpd/conf/httpd.conf 

134 Listen 443

# service httpd restart

在windows下 
打开ie   https://192.168.3.2

安装导出来的证书