目录
Httpd安装与基础配置
dnf list httpd
dnf -y install httpd
127.0.0.1
Systemctl status httpd
Systemctl start httpd //临时打开,重启之后就不行了
Systemctl status httpd
Systemctl enable httpd //开机自启
Tree/etc/www
cd/etc
ll
cd/
ll
tree/var/www
echo “welcome”>/var/www/html/index.html
getenforce
Setenforce 0 //关闭selinux
Systemctl stop firewalld //关闭防火墙
systemctl status firewalld //查看防火墙状态
systemctl stop firewalld //暂时关闭防火墙
基于多ip的多虚拟主机配置
systemctl start httpd
nmtui
198.168.100.11/24
198.168.100.12/24
198.168.100.13/24
198.168.100.2
198.168.100.2
设置完成后即可
nmcli connection up yexi
mkdir /var/www/html/ai
cd /var//www/html
ll
mkdir ca iot
ll
echo “192.168.100.11/24”>ai/index.html
echo “192.168.100.12/24”>ca/index.html
echo “192.168.100.13/24”>iot/index.html
cat ai/index.html
cat ca/index.html
cat iot/index.html
cd /
vim /etc/httpd/conf/httpd.conf
set nu
132g
<VirtualHost 192.168.100.11> //133行
DocumentRoot /var/www/html/ai
ServerName www.whit_ai.com
<Directory /var/www/html/ai>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.100.12>
DocumentRoot /var/www/html/ca
ServerName www.whit_ca.com
<Directory /var/www/html/ca>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.100.13>
DocumentRoot /var/www/html/iot
ServerName www.whit_iot.com
<Directory /var/www/html/ai>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
:wq //:w 存盘 :q退出 :wq 存盘退出
Systemctl restart httpd
基于主机域名的多虚拟主机配置
Nmtui
移除后两个ip地址
nmcli connection up yexi
vim /etc/hosts
192.168.100.11 www.whit_ai.com www.whit_ca.com www.whit_iot.com
Ping -c 4 www.whit_ai.com
Echo “welcome to ai”>/var/www/html/ai/index.html
Cat /var/www/html/ai/index.html
Echo “welcome to ca”>/var/www/html/ca/index.html
Echo “welcome to iot”>/var/www/html/iot/index.html
Vim /etc//httpd/conf/httpd.conf
<VirtualHost 192.168.100.11> //133行
DocumentRoot /var/www/html/ai
ServerName www.whit_ai.com
<Directory /var/www/html/ai>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.100.11>
DocumentRoot /var/www/html/ca
ServerName www.whit_ca.com
<Directory /var/www/html/ca>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.100.11>
DocumentRoot /var/www/html/iot
ServerName www.whit_iot.com
<Directory /var/www/html/ai>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
:wq //:w 存盘 :q退出 :wq 存盘退出
Systemctl restart httpd
基于端口号的多虚拟主机的配置
Vim /etc/httpd/conf/httpd.conf
:set nu //45行
Listen 6001
Listen 6002
Listen 6003
<VirtualHost 192.168.100.11::6001> //133行
DocumentRoot /var/www/html/ai
ServerName www.whit_ai.com
<Directory /var/www/html/ai>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.100.11::6002>
DocumentRoot /var/www/html/ca
ServerName www.whit_ca.com
<Directory /var/www/html/ca>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.100.11::6003>
DocumentRoot /var/www/html/iot
ServerName www.whit_iot.com
<Directory /var/www/html/ai>
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
:wq
vim /etc/hosts
删除192
:wq
Systemctl restart httpd
Journalctl -xe //不重要的一句话
Semanage port -l |grep http
Semanage port -a -t http_port_t -p tcp 6001
Semanage port -a -t http_port_t -p tcp 6002
Semanage port -a -t http_port_t -p tcp 6003
Semanage port -l|grep http
Systemctl restart httpd