1.安装httpd,并将访问apache服务器的首页修改为hello.html, 且内容为: “My Home Page is hello”
[root@AAA ~]# systemctl stop firewalld.service [root@AAA ~]# getenforce Enforcing [root@AAA ~]# setenforce 0 [root@AAA ~]# getenforce Permissive [root@AAA html]# echo 'My Home Page is hello' > home.html [root@AAA html]# ls home.html index.html <IfModule dir_module> #DirectoryIndex index.html DirectoryIndex home.html </IfModule> [root@AAA html]# curl 192.168.193.129 My Home Page is hello
2.虚拟主机:虚拟两台主机ip为100,200, 对应访问目录:/www/ip/100, /www/ip/200并创建首页文件index.html
[root@WHL ~]# nmcli connection modify ens160 +ipv4.addresses 192.168.193.100/24 [root@WHL ~]# nmcli connection modify ens160 +ipv4.addresses 192.168.193.200/24 [root@WHL ~]# nmcli connection up e e7c753f0-aa71-4ab5-8b54-ace0c085b2b0 ens160 [root@WHL ~]# nmcli connection up ens160 'Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8) [root@WHL ~]# mkdir -pv /www/ip{100,200} mkdir: created directory '/www' mkdir: created directory '/www/ip100' mkdir: created directory '/www/ip200' [root@WHL ~]# echo 'this is 100' > /www/ip ip100/ ip200/ [root@WHL ~]# echo 'this is 100' > /www/ip100/index.html [root@WHL ~]# echo 'this is 200' > /www/ip200/index.html [root@WHL ~]# vim /etc/httpd/conf.d/myhost.conf <VirtualHost 192.168.193.100:80> DocumentRoot "/www/ip100/" </VirtualHost> <VirtualHost 192.168.193.200:80> DocumentRoot "www/ip200" </VirtualHost> <Directory /www/ip> AllowOverride None Require all granted </Directory> [root@WHL ~]# systemctl restart httpd
3.配置不同端口的虚拟主机访问apache服务器
[root@WHL ~]# mkdir -p /www/port/{8000,9000} [root@WHL ~]# echo "this is page for port 8000" > /www/port/8000/index.html [root@WHL ~]# echo "this is page for port 9000" > /www/port/9000/index.html [root@WHL ~]# vim /etc/httpd/conf.d/myhost.conf Listen 8000 Listen 9000 <VirtualHost 192.168.193.100:8000> DocumentRoot "/www/port/8000" </VirtualHost> <VirtualHost 192.168.193.200:9000> DocumentRoot "www/port/9000" </VirtualHost> <Directory /www/port> AllowOverride None Require all granted </ Directory> [root@WHL ~]# systemctl restart httpd