RHCE之路配置网页及其子文件

第六天

配置web服务

架构c/s windows/RHEL-8.5linux

server主机配置

通过多ip配置多网站

注:要先进行挂载等一系列操作 RHCE之路web服务器_无所不知的神奇海螺的博客-CSDN博客

1.添加多个ip地址

[root@A ~]# nmcli connection modify ens160  ipv4.method manual ipv4.addresses 192.168.10.129/24 +ipv4.addresses 192.168.10.100/24 +ipv4.addresses 192.168.10.200/24 ipv4.gateway 192.168.10.2 ipv4.dns 114.114.114.114 connection.autoconnect yes

或者用图形界面

配置完记得网卡断开重连(用按钮)--- 可以用ip a查看

2.关闭防火墙

systemctl stop firewalld

setenforce 0

3.安装对应的服务软件Apahce http server

mount /dev/sr0 /mnt

yum install httpd

4.更改配置实现自定义设置

vim /etc/httpd/conf.d/vhosts.conf

[root@A ~]# vim /etc/httpd/conf.d/vhosts.conf

<VirtualHost 192.168.10.129:80>
        ServerName 192.168.10.129
        DocumentRoot /www/openlab --- 把子文件都放在openlab里
</VirtualHost>
<Directory /www> --- 给openlab的父目录加权限
        AllowOverride none  --- 不允许覆盖
        Require all granted --- 所有人都可以访问
</Directory>

[root@A ~]# mkdir -p /www/openlab
[root@A ~]# echo this is 192.168.10.129 > /www/openlab/index.html
[root@A ~]# systemctl stop firewalld
[root@A ~]# setenforce 0

添加两个子ip,192.168.10.100,192.168.10.200

[root@A ~]# nmcli connection up ens160

接着配置子文件

[root@A ~]# vim /etc/httpd/conf.d/vhosts.conf

<VirtualHost 192.168.10.129:80>
        ServerName 192.168.10.129
        DocumentRoot /www/openlab
</VirtualHost>
<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
<VirtualHost 192.168.10.100:80>
        ServerName 192.168.10.100
        DocumentRoot /www/nanhang
</VirtualHost>
<VirtualHost 192.168.10.200:80>
        ServerName 192.168.10.200
        DocumentRoot /www/jincheng
</VirtualHost>

5.根据配置创建资源文件

[root@A ~]# mkdir /www/{nanhang,jincheng}

[root@A ~]# echo this is 129 > /www/openlab/index.html
[root@A ~]# echo this is 100 > /www/nanhang/index.html
[root@A ~]# echo this is 200 > /www/jincheng/index.html

6.重启服务测试

[root@A ~]# systemctl resatrt httpd

浏览器访问

http://192.168.10.129

http://192.168.10.100

http://192.168.10.200

httpd -t --- 查看错误

多端口访问同一个ip

[root@A ~]# vim /etc/httpd/conf.d/vhosts.conf
LISTEN 8888 --- 监听端口
LISTEN 10000
<VirtualHost 192.168.10.129:8888>
        ServerName 192.168.10.129
        DocumentRoot /www/8888
</VirtualHost>
<VirtualHost 192.168.10.129:10000>
        ServerName 192.168.10.129
        DocumentRoot /www/10000
</VirtualHost>

[root@A ~]# mkdir /www/{8888,10000}

[root@A ~]# echo this is 8888 > /www/8888/index.html
[root@A ~]# echo this is 10000 > /www/10000/index.html

[root@A ~]# systemctl restart httpd

测试

[root@A ~]# curl http://192.168.10.129:8888

多域名访问一个ip

[root@A ~]# vim /etc/httpd/conf.d/vhosts.conf 
<VirtualHost 192.168.10.129:80>
        ServerName www.haha.com
        DocumentRoot /www/haha
</VirtualHost>
<VirtualHost 192.168.10.129:80>
        ServerName www.hehe.com
        DocumentRoot /www/hehe
</VirtualHost>

[root@A ~]# mkdir /www/{haha,hehe}
[root@A ~]# echo this is haha > /www/haha/index.html
[root@A ~]# echo this is hehe > /www/hehe/index.html
[root@A ~]# systemctl restart httpd

客户端主机解析域名(在linux上)

vim /etc/hosts

192.168.10.100 www.haha.com www.hehe.com

客户端主机解析域名(在windows上)

在运行里输入drivers找到etc,用记事本方式打开hosts

 

把ip和域名信息写入,保存退出即可

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值