[root@localhost fff]# openssl req -newkey rsa -nodes -keyout openlab.key -x509 -days 365 -out openlab.crt
Generating a RSA private key
......................................................................................................................+++++
..+++++
writing new private key to 'openlab.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]:86
State or Province Name (full name) []:ningxia
Locality Name (eg, city) [Default City]:yinchuan
Organization Name (eg, company) [Default Company Ltd]:openlab
Organizational Unit Name (eg, section) []:1
Common Name (eg, your name or your server's hostname) []:localhost
Email Address []:[email protected]
[root@localhost openlab]# vim /etc/httpd/conf.d/vhosts.conf
[root@localhost openlab]# cat /etc/httpd/conf.d/vhosts.conf
ServerName www.openlab.com
DocumentRoot /www/openlab
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/openlab.crt
SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
AllowOverride none
Require all granted
[root@localhost openlab]# mkdir -pv /www/openlab
[root@localhost openlab]# echo 这是一个https测试文件 > /www/openlab/index.html
[root@localhost openlab]# echo welcome to openlab!! >> /www/openlab/index.html
echo welcome to openlabcat /etc/httpd/conf.d/vhosts.conf >> /www/openlab/index.html
[root@localhost fff]# vim /etc/hosts
[root@localhost fff]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.138.135 www.openlab.com
[root@localhost openlab]# systemctl restart httpd
ServerName wwww.openlab.com
DocumentRoot /www/openlab
Alias /student /ce1
Alias /date /ce2
Alias /money /ce3
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/openlab.crt
SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
[root@localhost /]# mkdir -pv ce1
mkdir: 已创建目录 'ce1'
[root@localhost /]# mkdir -pv ce2
mkdir: 已创建目录 'ce2'
[root@localhost /]# mkdir -pv ce3
mkdir: 已创建目录 'ce3'
[root@localhost /]# echo 学生信息 > /ce1/index.html
[root@localhost /]# echo 教学资料 > /ce2/index.html
[root@localhost /]# echo 缴费网站 > /ce3/index.html
在学生信息网站的目录下进行配置
vim /etc/httpd/conf.d/vhosts.conf
AllowOverride none
AuthType basic
AuthName "login"
AuthUserfile /etc/httpd/users
Require user song
Require user tian
[root@localhost /]# htpasswd -c /etc/httpd/users tian
New password:
Re-type new password:
Adding password for user tian
[root@localhost /]# htpasswd /etc/httpd/users song
New password:
Re-type new password:
Adding password for user song
[root@localhost /]# cat /etc/httpd/users
tian:$apr1$7IBNs..3$SK/qV7wm/QZ/Tbj7NBgRs0
song:$apr1$BQQo.P6j$OktS6H0XaCbw23cGr5xIn/