搭建web服务器
目录
网站需求:
一、访问openlab网站
1、安装相应的包已配置好仓库
yum install httpd -y
关闭防火墙
yum install httpd -y
setenforce 0
挂载到本地磁盘
mount /dev/sr0 /mnt/
2、更改配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf
<VirtualHost 192.168.171.132:80>
Servername www.openlab.com
DocumentRoot /www/openlab
</VirtualHost>
<Directory /www/>
AllowOverride none
Require all granted
</Directory>
[root@localhost ~]# mkdir /var/www/openlab //创建对应的文件
[root@localhost ~]# echo welcome to openlab > /var/www/openlab/index.html //手动写入内容
[root@localhost conf.d]# vim /etc/hosts //在客户端修改hosts
[root@localhost conf.d]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.171.132 www.openlab.com
[root@localhost ~]# systemctl restart httpd //重启httpd服务
3、测试是否可以访问
二、3个子界面
1、创建对应的目录
wenjian[root@localhost ~]# mkdir /var/www/openlab/student
[root@localhost ~]# mkdir /var/www/openlab/data
[root@localhost ~]# mkdir /var/www/openlab/money
2、手动输入文件内容
[root@localhost ~]# echo xueshengxixin > /var/www/openlab/student/index.html
[root@localhost ~]# echo jiaoxueziliao >/var/www/openlab/data/index.html
[root@localhost ~]# echo jiaofei >/var/www/openlab/money/index.html
3、查看子网结果
三、指定用户访问和加密访问
1、指定用户访问student
(1)创建song和tian两个用户
[root@localhost ~]# htpasswd -c /etc/httpd/yonghu song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd -c /etc/httpd/yonghu tian
New password:
Re-type new password:
Adding password for user tian
(2)在配置文件中添加内容
[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf
[root@localhost ~]# cat /etc/httpd/conf.d/vhost.conf
<VirtualHost 192.168.171.132:80>
Servername www.openlab.com
DocumentRoot /var/www/openlab
</VirtualHost>
<Directory /var/www/openlab>
AllowOverride none
Require all granted
</Directory>
// 新添加的用户信息
<directory /var/www/openlab/student>
allowoverride none
authtype basic
authname "please login"
authuserfile /etc/httpd/yonghu
require user song tian
</directory>
(3)访问student
2、加密访问 money网站
(1)下载mod_ssl 软件包
[root@localhost ~]# yum install mod_ssl
(2)生成私钥文件和证书
[root@server ~]# cd /etc/pki/tls/private/
[root@server private]# openssl genrsa -aes128 2048 > jiami.key
[root@localhost certs]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl req -utf8 -new -key /etc/pki/tls/private/jiami.key -x509 -days 365 -out jiami.crt
(3)测试