基于域名的本地虚拟主机配置

配置server0 web服务,http://www0.example.com 自行做解析
网页:自定义,命名为index.html
来自192.168.162.0/24域的客户端可以访问web服务;
来自10.30.122.0/24域的客户端拒绝访问web服务。

将要用的网站放在一个目录下
此处为/var/www/html下的index.html
[root@server0 ~]# cat /var/www/html/index.html
www0
在防火墙添加服务或者80端口
[root@server0 ~]# firewall-cmd --permanent --add-service=http
success
[ root@server0~]# firewall-cmd --reload
success
[ root@server0~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client http ssh
ports:
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
在/etc/httpd/conf.d下写虚拟主机的配置文件,以.conf为结尾
< VirtualHost *:80 >
ServerName www0.example.com
DocumentRoot /var/www/html
< /VirtualHost >
< Directory /var/www/html >
< RequireAll >
Require all granted
Require not ip 10.30.122.0/24
< /RequireAll >
< /Directory >
重启服务systemctl restart httpd
(httpd -t 可查看语法错误)
在/etc/hosts文件里做本地解析工作
本地ip www0.example.com
测试:
[root@server0 ~]# links -dump http://www0.example.com
www0
或者
[root@server0 ~]# curl http://www0.example.com
www0

猜你喜欢

转载自blog.csdn.net/weixin_42275939/article/details/82686344
今日推荐