用vim进入配置文件找到listen 80并将其改成9999
vim httpd.conf
然后退出保存
按Esc键在数冒号加wq,
回车
重启httpd的端口
systemctl restart httpd
给防火墙添加端口号
firewall-cmd --permanent --add-port=9999/tcp
重加载防火墙
firewall-cmd --reload
查看防火墙列表
firewall-cmd --list-all
2、添加新的默认页面sorry.html,在默认主页不能访问是显示“很抱歉...该网站正在维护中,请您在 4月1号之后在访问,感谢您的支持”
首先进入主配置文件/etc/httpd/conf/找到httpd.conf
cd /etc/httpd/conf
再用vim进入配置文件找到DirectoryIndex并在后面添加sorry.html
vim httpd.conf
/index
默认发布目录/var/www/html并创建和编辑sorry.html
vim /var/www/html/sorry.html
测试将默认主页该名称index1.html
mv /var/www/html/index.html /var/www/html/index1.html
在浏览器中实验一下
3、配置三台虚拟主机,用基于端口的方式配置。
1.修改httpd的主配置文件,vim /etc/httpd/conf/httpd.conf
然后添加一行Listen 81
Listen 82
Listen 83
然后退出保存
按Esc键在数冒号加wq,
回车
重启httpd的端口
systemctl restart httpd
2.创建所需的根文件
mkdir /var/www/net/http1 -p
mkdir /var/www/net/http2 -p
mkdir /var/www/net/http3 -p
创建HTML文件并写入内容
echo "this is http1:81 web" >> http1/index.html
echo "this is http2:82 web" >> http2/index.html
echo "this is http3:83 web" >> http3/index.html
运用cat查看内容
cat index.html
3.修改虚拟主机配置文件,添加如下内容
<VirtualHost 192.168.159.2:81>
DocumentRoot /var/www/net/http1
ServerName www.http1.com
</VirtualHost>
<VirtualHost 192.168.159.2:82>
DocumentRoot /var/www/net/http2
ServerName www.160.com
</VirtualHost>
<VirtualHost 192.168.159.2:83>
DocumentRoot /var/www/net/http3
ServerName www.http3.com
</VirtualHost>
4.检查语法
httpd -t
5.防火墙添加端口号firewall-cmd --permanent --add-port=81/tcp
重加载防火墙 firewall-cmd --reload
防火墙添加端口号firewall-cmd --permanent --add-port=82/tcp
重加载防火墙 firewall-cmd --reload
防火墙添加端口号firewall-cmd --permanent --add-port=83/tcp
重加载防火墙 firewall-cmd --reload
查看防火墙列表
firewall-cmd --list-all
查看当前端口号
netstat -atunp |grep httpd
6.访问测试:在浏览器上输入:192.168.139.128:81