1. Configure el archivo de hosts
vim /etc/hosts
172.19.74.12 wenlong1.wen.com
172.19.74.12 wenlong2.wen.com
172.19.74.12 wenlong3.wen.com
2. Cree un directorio de sitios web y escriba contenido diferente en index.html
mkdir -p /home/www/{wenlong1,wenlong2,wenlong3}
echo "wenlong1 page" > /home/www/wenlong1/index.html
echo "wenlong2 page" > /home/www/wenlong2/index.html
echo "wenlong3 page" > /home/www/wenlong3/index.html
3. Configure la información del host virtual en el archivo de configuración de Apache.
vim /etc/httpd/conf/httpd.conf
<Directory "/home/www/wenlong1">
Require all granted
</directory>
<VirtualHost 172.19.74.12>
DocumentRoot "/home/www/wenlong1"
ServerName "wenlong1.wen.com"
</VirtualHost>
<Directory "/home/www/wenlong2">
Require all granted
</directory>
<VirtualHost 172.19.74.12>
DocumentRoot "/home/www/wenlong2"
ServerName "wenlong2.wen.com"
</VirtualHost>
<Directory "/home/www/wenlong3">
Require all granted
</directory>
<VirtualHost 172.19.74.12>
DocumentRoot "/home/www/wenlong3"
ServerName "wenlong3.wen.com"
</VirtualHost>
# 检查配置文件中语法是否正确
httpd -t
4. Reinicie Apache y descubrió que el acceso 403 se denegó, se sospecha que es causado por el contexto de selinux
Nota: Si le resulta problemático, puede desactivar selinux. Por favor, Baidu para obtener más detalles. No tengo nada que hacer aquí, he modificado el contexto de seguridad del sitio.
systemctl restart httpd
curl wenlong1.wen.com/index.html
# 查看selinux状态,发现是强制模式
getenforce
# 为验证是否因selinux引起,将状态改为宽容模式,再次验证
setenforce 0
5. Determine el problema causado por selinux, modifique el contexto de selinux
# 将selinux设置为强制模式
setenforce 1
# 创建新的默认规则,修改selinux上下文
# 下边命令在 /etc/selinux/targeted/contexts/files/file_contexts.local中加了一条默认规则
semanage fcontext -a -t httpd_sys_content_t "/home/www(/.*)?"
Observaciones: La captura de pantalla de /etc/selinux/targeted/contexts/files/file_contexts.local es la siguiente
# 按照上边加的规则,递归将新的上下文应用到/home/www/文件夹和它的子目录
restorecon -R /home/www/
# 再次测试,并测试其它虚拟主机,参看下边图片
curl wenlong1.wen.com/index.html