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

配置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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值