赞
踩
yum -y install httpd
systemctl start httpd
systemctl status httpd \\查看服务状态
systemctl stop firewalld.service \\关闭防火墙
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=80/udp
firewall-cmd --reload
firewall-cmd --query-port=80/tcp
yes
firewall-cmd --query-port=80/udp
yes
创建虚拟目录的优点有:便于访问、便于移动站点中的目录、能灵活加大磁盘空间、安全性好。使用Alias选项可以创建虚拟目录。
mkdir -p /var/www/motonhtml
mkdir -p /var/www/mohtml
echo "Hello Word! moton.">/var/www/motonhtml/index.html
echo "good night,Mr.mo">/var/www/mohtml/index.html
vim /etc/httpd/conf/httpd.conf
Alias /moton "/var/www/motonhtml"
Alias /mo "/var/www/mohtml"
chcon -R -t httpd_sys_content_t /var/www/
getsebool -a |grep httpd \\查看与httpd相关的安全策略
setsebool -P httpd_enable_homedirs on \\httpd允许访问用户主目录
getsebool -a | grep httpd_enable_homedir
systemctl restart httpd
#三、虚拟主机配置
nmcli con m ens33 +ipv4.address "192.168.117.118/24,192.168.117.119/24"
nmcli d d ens33
nmcli con up ifname ens33
mkdir -p /var/www/moton_ip118
mkdir - p /var/www/mo_ip119
echo "this is moton_ip118."> /var/www/moton_ip118/index.html
echo "this is mo_ip119." > /var/www/mo_ip119/index.html
//编辑配置文件
vim /etc/httpd/conf.d/httpd-vhosts.conf
添加以下内容:
<VirtualHost 192.168.117.118>
DocumentRoot "/var/www/moton_ip118/"
</VirtualHost>
<VirtualHost 192.168.117.119>
DocumentRoot "/var/www/mo_ip119/"
</VirtualHost>
systemctl restart httpd
测试在windows浏览器中输入IP
mkdir /var/www/moton
mkdir /var/www/mo
echo "this is moton." > /var/www/moton/index.html
echo "this is Mo Colloge." > /var/www/mo/index.html
vim /etc/httpd/conf.d/httpd-vhosts.conf
//写入以下内容: <VirtualHost 192.168.117.118:80> DocumentRoot "/var/www/moton/" ServerName www.moton.com </VirtualHost> <VirtualHost 192.168.117.119:80> DocumentRoot "/var/www/moton/" ServerName www.mo.com </VirtualHost>
systemctl restart httpd
vim /etc/hosts
添加以下内容
192.168.117.118 www.moton.com
192.168.117.119 www.mo.com
mkdir /var/www/motonport
mkdir /var/www/moport
echo "this is motonport.">/var/www/motonport/index.html
echo "this is moport."> /var/www/moport/index.html
vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost 192.168.117.118:8892>
DocumentRoot "/var/www/motonport/"
</VirtualHost>
<VirtualHost 192.168.117.119:1666>
DocumentRoot "/var/www/moport/"
</VirtualHost>
vim /etc/httpd/conf/httpd.conf
[root@pc1 www]# systemctl restart httpd (有可能报错,可以先进行下一步,再重启)
setenforce 0
vim /etc/httpd/conf.d/userdir.conf
mkdir /var/www/user1/public_html
mkdir /var/www/user2/public_html
echo "this is user1."> /var/www/user1/public_html/index.html
echo "this is user2."> /var/www/user2/public_html/index.html
chmod 711 /var/www/user1
chmod 711 /var/www/user2
chmod 755 /var/www/user1/public_html
chmod 755 /var/www/user1/public_html
chcon -R -t httpd_sys_content_t /var/www/user1
chcon -R -t httpd_sys_content_t /var/www/user2
systemctl stop firewalld
systemctl restart httpd
d 711 /var/www/user2
chmod 755 /var/www/user1/public_html
chmod 755 /var/www/user1/public_html
## 步骤5:为文件夹设置安全上下文
chcon -R -t httpd_sys_content_t /var/www/user1
chcon -R -t httpd_sys_content_t /var/www/user2
## 步骤6:关闭防火墙(或开放80)端口
systemctl stop firewalld
## 步骤7:重启服务
systemctl restart httpd
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。