[Linux]演習--- Webサーバーの包括的な実験

実験要件:

     openlabのWebサイトを構築します。

           1.ドメイン名www.openlab.comに基づいて、openlabへようこそとしてWebサイトのコンテンツにアクセスできます!!!

           2.会社が学生情報、教材、支払いWebサイトをそれぞれ表示するための3つの仮想Webサイトディレクトリを作成します。

        (www.openlab.com/student Webサイトに基づいて学生情報にアクセスし、www.openlab.com / data Webサイトに基づいて教材にアクセスし、www.openlab.com / moneyに基づいて支払いWebサイトにアクセスします)

           3.学生情報ウェブサイトには、歌と天人のみがアクセスでき、他のウェブサイトのすべてのユーザーがアクセスできます。

                httpsアクセスに基づくデータ暗号化を実現するには、支払いWebサイトにアクセスしてください。

 

実験手順:

1. httpdパッケージ(httpサービス)とmod_sslパッケージをインストールします(特にApacheサーバーにパスワード保護を提供します)

[root@localhost conf.d]# yum install -y httpd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:23:32 前,执行于 2020年11月03日 星期二 16时30分44秒。
Package httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 is already installed.
依赖关系解决。
无需任何处理。
完毕!
[root@localhost conf.d]# yum install -y mod_ssl
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:02:33 前,执行于 2020年11月03日 星期二 16时30分44秒。
Package mod_ssl-1:2.4.37-10.module+el8+2764+7127e69e.x86_64 is already installed.
依赖关系解决。
无需任何处理。
完毕!

2.仮想ホスト構成ファイルを書き込みます

[root@localhost ~]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# vim vhost-openlab.conf 

<VirtualHost 192.168.74.130:80>                       //虚拟主机模块(基于http访问)
        DocumentRoot /www/http                        //网页文件主目录
        ServerName www.openlab.com                    //主机名(此处为域名)
        alias /student  /openlab/student              //别名
        alias /data  /openlab/data                    //别名
</VirtualHost>

<VirtualHost 192.168.74.130:443>                      //虚拟主机模块(基于https访问)
        DocumentRoot /www/http                        //网页文件主目录
        ServerName www.openlab.com                    //主机名(此处为域名)
        alias /money  /openlab/money                  //别名
        SSLEngine on                                  //SSL认证开启
        SSLCertificateFile /etc/pki/tls/certs/zhengshu.crt       //证书文件存放位置
        SSLCertificateKeyFile /etc/pki/tls/certs/zhengshu.key    //私钥文件存放位置
</VirtualHost>

<Directory /www/http>                                 //目录模块(权限限定)
        AllowOverride none                            //不允许覆盖
        Require all granted                           //允许所有访问此目录
</Directory>

<Directory /openlab/student>                          //目录模块(权限限定)
        AllowOverride none                            //不允许覆盖
        Authtype basic                                //基本认证类型(账号)
        Authname "Please login:"                      //提示信息(双引号内添加)
        Authuserfile /etc/httpd/users                 //用户认证文件(有用户名和密码)
        Require user song tian                        //允许访问服务器名单
</Directory>

<Directory /openlab/data>                             //目录模块(权限限定)
        AllowOverride none                            //不允许覆盖
        Require all granted                           //允许所有人访问服务器
</Directory>

<Directory /openlab/money>                            //目录模块(权限限定)
        AllowOverride none                            //不允许覆盖
        Require all granted                           //允许所有人访问服务器
</Directory>              

 3.証明書を作成します

# /etc/pki/tls/certs/目录下需要有Makefile文件可自制证书
# rhel8上没有此文件,若需要可从rhel7上复制该文件

[root@localhost conf.d]# cd /etc/pki/tls/certs/
[root@localhost certs]# ll
总用量 20
lrwxrwxrwx. 1 root root   49 8月  13 2018 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx. 1 root root   55 8月  13 2018 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rw-r--r--. 1 root root 3952 10月 29 20:49 localhost.crt
-rw-r--r--. 1 root root 2388 10月 29 20:20 Makefile
-rw-r--r--. 1 root root 2236 11月  2 14:02 postfix.pem
[root@localhost certs]# make zhengshu.crt                    //制作名为zhengshu的证书
umask 77 ; \
/usr/bin/openssl genrsa -aes128 2048 > zhengshu.key
Generating RSA private key, 2048 bit long modulus (2 primes)
................................................+++++
.......................+++++
e is 65537 (0x010001)
Enter pass phrase:                                                 //输入密码
Verifying - Enter pass phrase:                                     //确认密码
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key zhengshu.key -x509 -days 365 -out zhengshu.crt -set_serial 0
Enter pass phrase for zhengshu.key:                               //与上述密码相同
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:ZG                                //国家代码
State or Province Name (full name) []:SX                            //省份
Locality Name (eg, city) [Default City]:Xi'an                       //城市
Organization Name (eg, company) [Default Company Ltd]:openlab       //公司名
Organizational Unit Name (eg, section) []:RHCE                      //部门或组织名
Common Name (eg, your name or your server's hostname) []:www.test.com  //主机名
Email Address []:[email protected]                    //邮箱

4.ユーザーを作成します

[root@localhost ~]# htpasswd -c /etc/httpd/users song    //添加用户并将密码信息存入users目录下
New password: 
Re-type new password: 
Adding password for user song
[root@localhost ~]# htpasswd /etc/httpd/users tian      //添加用户并将密码信息存入users目录下
New password: 
Re-type new password: 
Adding password for user tian
[root@localhost ~]# htpasswd /etc/httpd/users li        //添加用户并将密码信息存入users目录下
New password: 
Re-type new password: 
Adding password for user li
[root@localhost ~]# htpasswd /etc/httpd/users zhao      //添加用户并将密码信息存入users目录下
New password: 
Re-type new password: 
Adding password for user zhao

 5.Webページファイルディレクトリを作成します

[root@localhost ~]# mkdir -p /www/http
[root@localhost http]# mkdir -p  /openlab/{student,data,money}

6.Webページファイルのコンテンツを定義します

[root@localhost conf.d]# echo welcome to openlab! > /www/http/index.html   //网页文件主界面
[root@localhost http]# echo 学生信息 > /openlab/student/index.html  //虚拟子目录:学生信息界面
[root@localhost http]# echo 教学资料 > /openlab/data/index.html     //虚拟子目录:教学资料界面
[root@localhost http]# echo 缴费通道 > /openlab/money/index.html    //虚拟子目录:缴费通道界面

7.仮想マシンのキャッシュファイルをこのドメイン名解決エントリ(/ etc / hosts)に書き込みます

[root@localhost http]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.74.130 www.openlab.com           //添加此条信息

 8.ローカルホストキャッシュファイルをこのドメイン名解決エントリ(C:\ Windows \ System32 \ drivers \ etc \ hosts)に書き込みます。

9.ファイアウォールとselinuxのセキュリティメカニズムをオフにします

[root@localhost conf.d]# systemctl stop firewalld         //关闭防火墙
[root@localhost conf.d]# setenforce 0                     //关闭selinux
[root@localhost conf.d]# systemctl status firewalld       //查看防火墙状态
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@localhost conf.d]# getenforce                       //查看selinux状态
Permissive

10.httpdサービスを再起動します

[root@localhost conf.d]# systemctl restart httpd
Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ******

 11.テスト

    ①ウェブページファイルのメインインターフェース

[root@localhost conf.d]# curl http://www.openlab.com
welcome to openlab!

        

    ②学生情報インターフェース

[root@localhost conf.d]# curl http://www.openlab.com/student/ -u song    //song用户可访问
Enter host password for user 'song':
学生信息
[root@localhost conf.d]# curl http://www.openlab.com/student/ -u tian   //tian用户可访问
Enter host password for user 'tian':
学生信息
[root@localhost conf.d]# curl http://www.openlab.com/student/ -u li    //li用户被拒绝
Enter host password for user 'li':
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
[root@localhost conf.d]# curl http://www.openlab.com/student/ -u zhao    //zhao用户被拒绝
Enter host password for user 'zhao':
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>

      

 

    ③教育情報インターフェース

[root@localhost conf.d]# curl http://www.openlab.com/data/
教学资料

     

 

    ④ペイメントチャネルインターフェース

[root@localhost conf.d]# curl -k https://www.openlab.com/money/
缴费通道

   

 

実験が完了しました!

おすすめ

転載: blog.csdn.net/trichloromethane/article/details/109472836