服务器是rhel7.4
已经换完阿里源 更新完系统 centos7换阿里源
根据视频内容进行操作
安装httpd软件包
yum install httpd -y
启动服务
systemctl start httpd
systemctl enable httpd
systemctl status httpd
配置防火墙允许httpd通过防火墙
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
firewall-cmd --list-all
getenforce
Enforcing
setenforce 0
getenforce
Permissive
配置ip地址 添加IP 我这个本来已经设置了静态IP 已经有一个ip地址了所以我就只是又添加了子端口号
ifconfig ens33:1 192.168.1.101
修改IP地址和主机名对应的列表问价
vim /etc/hosts
192.168.1.100 www.king.com www.lyz.com
前期已经完成,默认网页的配置
实训一
cd /etc/httpd/conf.d
vim userdir.conf
注释 UserDir disabled
将下面的UserDir public_html
创建用户并进入创建的用户目录下
useradd user1
cd /home/user1
mkdir public_html
cd public_html
vim index.html
user1 homepage!
chmod o+x /home/user1
通过 ls -ld 文件夹名字 查看文件夹的读取和权限
systemctl restart httpd
firefox http://192.168.1.100
http://192.168.1.100/~user1/
实训二
mkdir /data/private
mkdir /data/private -p
vim /data/private/index.html
private page!
vim /etc/httpd/conf/httpd.conf
add
Alias /private /data/private
<Directory "/data/private">
AllowOverride None
AuthType Basic
AuthName "Input user name:"
AuthUserFile /etc/httpd/conf/.htpaswd
Require valid-user
</Directory>
htpasswd -c /etc/httpd/conf/.htpasswd kingliu
liu
liu
systemctl restart httpd
-c 就是创建新的文件
实训三
mkdir /dir1/test/ -p
vim /dir1/test/index.html
test page!
vim /etc/httpd/conf/httpd.conf
Alias /test /dir1/test
<Directory "/dir1/test">
AllowOverride None
Order allow,deny #先允许后拒绝
Allow from lyz.com #允许来自lyz.com或者192.168.1.0/24网段的链接
Allow from 192.168.1.0/24
Require all granted
</Directory>
systemctl restart httpd
结果
实训四
mkdir /var/www/ip100
mkdir /var/www/ip101
vim /var/www/ip100/index.html
ip100page!
vim /var/www/ip101/index.html
ip101page!
cd /etc/httpd/conf.d/
vim vhost.conf #这个是默认没有的,是自己创建的
<VirtualHost 192.168.1.100>
DocumentRoot /var/www/ip100
</VirtualHost>
<VirtualHost 192.168.1.101>
DocumentRoot /var/www/ip101
</VirtualHost>
systemctl restart httpd
结果
实训五
mkdir /var/www/lyz
mkdir /var/www/king
vim /var/www/lyz/index.html
lyz.com page
vim /var/www/king/index.html
king.com page
cd /etc/httpd/conf.d/
vim vhost.conf
<VirtualHost 192.168.1.100>
DocumentRoot /var/www/lyz
ServerName www.lyz.com
</VirtualHost>
<VirtualHost 192.168.1.100>
DocumentRoot /var/www/king
ServerName www.king.com
</VirtualHost>
systemctl restart httpd
结果
重启之后会出现firbidden
setenforce 0
getenforce
Permissive