搭建网站练习

Linux搭建网站练习:

rhet8.2

一:

建立两个基于ip地址访问的网站,要求如下:
1、该网站ip地址的主机位为100,设置DocumentRoot为/www/ip/100,网页内容为:this is 100。
2、该网站ip地址主机位为200,设置DocumentRoot为/www/ip/200,网页内容为:this is 200。

第一步:添加两个新的ip

[root@localhost ~]# nmcli connection modify ens160 +ipv4.address 192.168.18.100/24
[root@localhost ~]# nmcli connection modify ens160 +ipv4.address 192.168.18.200/24
[root@localhost ~]# nmcli connection up ens160

第二步:创建两个网页的根目录,并定义网页内容

[root@localhost ~]# mkdir -pv /www/ip/{100,200}
mkdir: 已创建目录 '/www'
mkdir: 已创建目录 '/www/ip'
mkdir: 已创建目录 '/www/ip/100'
mkdir: 已创建目录 '/www/ip/200'
[root@localhost ~]# echo this is 100 > /www/ip/100/index.html
[root@localhost ~]# echo this is 200 > /www/ip/200/index.html

第三步:定义基于不同的ip地址来访问网站的配置文件

[root@localhost conf.d]# vim /etc/httpd/conf.d/host.conf
<VirtualHost 192.168.18.100:80>
        DocumentRoot /www/ip/100
        ServerName 192.168.18.100
</VirtualHost>


<VirtualHost 192.168.18.200:80>
        DocumentRoot /www/ip/200
        ServerName 192.168.18.200
</VirtualHost>

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>

第四步:关闭防火墙,重启httpd服务

[root@localhost conf.d]# systemctl stop firewalld
[root@localhost conf.d]# setenforce 0
[root@localhost conf.d]# systemctl restart httpd

第五步:验证

[root@localhost conf.d]# curl 192.168.18.100
this is 100
[root@localhost conf.d]# curl 192.168.18.200
this is 200

二:

建立两个基于不同端口访问的网站,要求如下:

1、建立一个使用web服务器默认端口的网站,设置DocumentRoot为/www/port/80,网页内容为:the port is 80。

2、建立一个使用10000端口的网站,设置DocumentRoot为/www/port/10000,网页内容为:the port is 10000。

步骤:
1.添加一个新的 IP地址
2.创建网页的根目录,并定义两个网页内容
3.定义基于不同的端口来访问网站的配置的文件
4.关闭防火墙,重启httpd服务。
5.验证

[root@localhost ~]# nmcli connection modify ens160 +ipv4.address 192.168.18.18/24
[root@localhost ~]# nmcli connection up ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5)
[root@localhost ~]# mkdir -pv /www/port/{80,10000}
mkdir: 已创建目录 '/www/port'
mkdir: 已创建目录 '/www/port/80'
mkdir: 已创建目录 '/www/port/10000'
[root@localhost ~]# echo this port is 80 > /www/port/80/index.html
[root@localhost ~]# echo this port is 10000 > /www/port/10000/index.html
[root@localhost ~]# vim /etc/httpd/conf.d/host1.conf

<VirtualHost 192.168.18.18:80>
        DocumentRoot /www/port/80
        ServerName 192.168.18.18
</VirtualHost>

listen 10000
<VirtualHost 192.168.18.18:10000>
        DocumentRoot /www/port/10000
        ServerName 192.168.18.18
</VirtualHost>

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>

~                                                                                                                                                               
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# curl 192.168.18.18:80
this port is 80
[root@localhost ~]# curl 192.168.18.18:10000
this port is 10000

三:

建立两个基于域名访问的网站,要求如下:

1、新建一个网站,域名为www.ceshi.com,设置DocumentRoot为/www/name,网页内容为this is test。

2、新建一个网站,域名为rhce.first.day,同时可通过ce.first.day访问,设置DocumentRoot为/www/ce,网页内容为:today is first day of class。
第一步:添加新的ip
第二步:创建两个网页文件根目录,并定义网页内容
第三步:定义基于不同域名的网页配置文件
第四步:在Linux中添加域名
第五步:关闭防火墙,重启httpd服务
第六步:验证

[root@localhost ~]# nmcli connection modify ens160 +ipv4.address 192.168.18.180/24
[root@localhost ~]# nmcli connection modify ens160 +ipv4.address 192.168.18.190/24
[root@localhost ~]# nmcli connection up ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/7)
[root@localhost ~]# mkdir -pv /www/{name,ce}
mkdir: 已创建目录 '/www/name'
mkdir: 已创建目录 '/www/ce'
[root@localhost ~]# echo this is test > /www/name/index.html
[root@localhost ~]# echo today is first day of class > /www/ce/index.html
[root@localhost ~]# vim /etc/httpd/conf.d/host2.conf
<VirtualHost 192.168.18.180:80>
        DocumentRoot /www/name
        ServerName www.ceshi.com
</VirtualHost>


<VirtualHost 192.168.18.190:80>
        DocumentRoot /www/ce
        ServerName rhce.first.day
        ServerName ce.first.day
</VirtualHost>

<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
[root@localhost name]# vim /etc/hosts
192.168.18.180   www.ceshi.com
192.168.18.190   rhce.first.day
192.168.18.190   ce.first.day
[root@localhost name]# curl www.ceshi.com
this is test
[root@localhost name]# curl rhce.first.day
today is first day of class
[root@localhost name]# curl ce.first.day
today is first day of class
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值