linux中搭建基于http协议静态网站

目录

一、搭建静态网站——基于http协议的静态网站

1.安装httpd,并将访问apache服务器的首页修改为hello.html, 且内容为: "My Home Page is hello"

2.虚拟主机:虚拟两台主机ip为100,200, 对应访问目录:/www/ip/100, /www/ip/200            并创建首页文件index.html 

3.配置不同端口的虚拟主机访问apache服务器


一、搭建静态网站——基于http协议的静态网站

1.安装httpd,并将访问apache服务器的首页修改为hello.html, 且内容为: "My Home Page is hello"

首先安装httpd软件

再修改服务器首页

[root@good html]# mv index.html hello.html

然后修改内容

[root@localhost ~]# echo My Home Page is hello > /var/www/html/hello.html

验证:

2.虚拟主机:虚拟两台主机ip为100,200, 对应访问目录:/www/ip/100, /www/ip/200
            并创建首页文件index.html 

  • 第一步,先添加两个ip地址
[root@localhost ~]#nmcli connection modify static +ipv4.addresses 192.168.109.131/24 ipv4.gateway 192.168.109.1 ipv4.method manual connection.autoconnect yes

[root@localhost ~]# nmcli connection modify static +ipv4.addresses 192.168.109.132/24

[root@localhost ~]# nmcli connection up static
  • 第二步,创建两个网页文件根目录,并定义网页内容
[root@localhost ~]# mkdir -pv /www/ip/{100,200}

[root@localhost ~]# echo this is 100 > /www/ip/100/index.html

[root@localhost ~]# echo this is 200 > /www/ip/200/index.html

[root@server html]# setenforce 0

[root@server html]# getenforce

Permissive
  • 第三步,定义基于不同ip地址来访问网站的配置文件
  • [root@good ~]# cd /etc/httpd/conf.d
    
    [root@good conf.d]# vim myhosts.conf 

 重启httpd

最后验证:

 

3.配置不同端口的虚拟主机访问apache服务器

第一步: 创建文件根目录

[root@localhost ~]# mkdir -pv /www/port/{9090,9091}

[root@localhost ~]# echo the port is 9090 > /www/port/9090/index.html

[root@localhost ~]# echo the port is 9091 > /www/port/9091/index.html

第二步: 基于不同端口来访问网站的配置文件

 重启服务

验证:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值