首先关闭防火墙和selinux,创建网页目录并写入本地
[root@server ~]# setenforce 0
setenforce: SELinux is disabled
[root@server ~]# systemctl stop firewalld
[root@server ~]# yum install httpd -y
[root@server ~]#
[root@server ~]# mkdir -p /www/openlab
[root@server ~]# echo 'welcome' > /www/openlab/index.html
[root@server ~]# vim /etc/hosts
[root@server ~]#
192.168.239.128 www.openlab.com
编辑http的主配置文件,并写入内容,重启。
[root@server ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.239.128>
DocumentRoot /www/openlab
ServerName "www.openlab.com"
<Directory /www/openlab>
AllowOverride None
require all granted
</Directory>
</VirtualHost>
[root@server ~]# systemctl restart httpd
创建三个子网站:
www.openlab.com/student 网站访问学生信息
www.openlab.com/data网站访问教学资料
www.openlab.com/money 网站访问缴费网站
[root@server conf]# mkdir /www/openlab/data
[root@server conf]# echo 'data' > /www/openlab/data/index.html
[root@server conf]# vim /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.239.128>
DocumentRoot /www/openlab
alias /data /www/openlab/data
ServerName "www.openlab.com"
</VirtualHost>
<Directory /www/openlab>
AllowOverride none
require all granted
</Directory>
<Directory /www/openlab/data>
AllowOverride none
require all granted
</Directory>
[root@server www]# systemctl restart httpd
添加用户并增加用户密码访问控制
[root@server ~]# mkdir /www/openlab/student/
[root@server ~]# echo 'student' > /www/openlab/student/index.html
[root@server ~]# chmod 755 -R /www/openlab/student
[root@server ~]# useradd biexing
[root@server ~]# passwd biexing
更改用户 biexing 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@server ~]# htpasswd -c /etc/httpd/passwd biexing
New password:
Re-type new password:
Adding password for user biexing
[root@server ~]# vim /etc/httpd/conf/httpd.conf
[root@server ~]# systemctl restart httpd
[root@server ~]#
<Directory /www/openlab/student>
Authtype Basic
AuthName "student"
AuthUserFile /etc/httpd/passwd
Require user song tian
</Directory>
[root@server ~]# mkdir /www/openlab/money
[root@server ~]# echo 'money' > /www/openlab/money/index.html
[root@server ~]# chmod 755 -R /www/openlab/money
[root@server ~]# yum install mod_ssl -y
[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/openlab.key
Enter PEM pass phrase: #123456
Verifying - Enter PEM pass phrase:
[root@server ~]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt
Enter pass phrase for /etc/pki/tls/private/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) []:shanxi
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) []:localhost
Email Address []:2914776784@qq.com
[root@server ~]#
[root@server ~]# vim /etc/httpd/conf/httpd.conf
[root@server ~]# systemctl restart httpd
🔐 Enter TLS private key passphrase for 192.168.239.128:443 (RSA) : #123456
[root@server ~]#
<<'<VirtualHost 192.168.239.128:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/openlab.crt
SSLCertificatekeyFile /etc/pki/tls/private/openlab.key
ServerName 192.168.239.128
DocumentRoot /www/openlab
alias /money /www/openlab/money
</VirtualHost>
<Directory /www/openlab/money>
AllowOverride none
require all granted
</Directory>'