一、实现一个web服务器

1、安装web服务

yum -y install httpd

image.png

2、配置对应域名

我们可以在/etc/http/conf/ /etc/http/conf.d/ /etc/http/conf.modules.d/ 这三个目录下创建以.conf为结尾的文件,在重启web服务时就会自动读取配置文件。

    DocumentRoot "/var/www/html"    ServerName system1.group8.example.com       
(下列权限对应的目录)             
                   Require all granted (允许所有)                   Require not host .my133t.org (禁止某一个域)             
              
(不同的权限对应不同的目录)            Require all denied (禁止所有)            Require local(只允许本地)        

image.png

然后测试的时候要关闭防火墙以及selinux,或者通过设置防火墙和期望值来允许,这里就直接全部关闭了

3、客户端测试

curl system1.group8.example.com

image.png

curl system1.group8.example.com/private/

image.png

让我们试一下本机连接

curl system1.group8.example.com/private/(后面‘/’一定要加)

image.png

不带‘/’的后果(大家请注意)

image.png


二、配置安全web服务器

1、首先安装安全协议包mod_ssl

yum -y install mod_ssl

image.png

安装完成包之后可以在/etc/httpd/conf.d/目录下发现一个为ssl.conf文件

image.png

vim /etc/httpd/conf.d/ssl.conf

image.png

从里面取出这五行代码

image.png

2、配置配置文件

(安全协议的端口为443端口)    DocumentRoot "/var/www/html"    ServerName system1.group8.example.com       
             
                   Require all granted                   Require not host .my133t.org             
               SSLEngine on        SSLProtocol all -SSLv2 -SSLv3        SSLCertificateFile /etc/pki/tls/certs/system1.crt (已经签名的证书)        SSLCertificateKeyFile /etc/pki/tls/private/system1.key (证书的密钥)        SSLCACertificateFile /etc/pki/tls/certs/ssl-ca.crt(此证书的CA认证中心)

image.png

重新启动httpd服务

systemctl restart httpd

image.png

3、客户端测试

curl -k +测试地址  (curl 中的 -k 为忽视证书的合法性测试)

image.png


三、配置虚拟主机

1、配置配置文件,添加一个新的以端口,地址,或者域名不同的虚拟主机,这里以域名为列子

vim /etc/httpd/conf.d/httpd-vhosts.conf
    DocumentRoot "/var/www/virtual" (新的DocumentRoot目录)    ServerName ceshi.com                      (不同的域名)       
        (对该目录做的权限)             
                   Require all granted             
               
   (目录下的子目录不同权限)            Require all denied            Require local        

image.png

重新启动httpd服务

systemctl restart httpd

2、客户端测试

curl ceshi.com

image.png


四、基于AllowOverride实现认证

1、配置配置文件

DocumentRoot "/var/www/html/admin"ServerName haha.com
        AllowOverride none        AuthType Basic        AuthName "Please login"        AuthUserfile "/etc/httpd/conf/.htpasswd"        Require user xixi

image.png

2、添加用户xixi

vim /etc/httpd/conf/.htpasswd

image.png

image.png

htpasswd -b -c -m /etc/httpd/conf/.htpasswd xixi centos

image.png

htpasswd -b -m /etc/httpd/conf/.htpasswd haha redhat

image.png

3、客户端测试

image.png

image.png