一、搭建静态网站——基于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地址来访问网站的配置文件
1. [root@good ~]# cd /etc/httpd/conf.d 2. 3. [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
- 第二步: 基于不同端口来访问网站的配置文件
- 重启服务
验证: