安装httpd,并将访问apache服务器的首页修改为hello.html, 且内容为: “My Home Page is hello”
[root@rhcsa ~]# yum install httpd -y
[root@rhcsa ~]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
[root@rhcsa ~]# systemctl start httpd
[root@rhcsa ~]# cd /var/www/html/
[root@rhcsa html]# vim hello.html
[root@rhcsa html]# cd /etc/httpd/conf.d
[root@rhcsa conf.d]# vim welcome.conf
# 修改文件为Alias /.noindex.html /usr/share/httpd/noindex/hello.html
[root@rhcsa conf.d]# cd /etc/httpd/conf
[root@rhcsa conf]# vim httpd.conf
修改文件
<IfModule dir_module>
DirectoryIndex hello.html
</IfModule>
[root@rhcsa conf]# systemctl restart httpd
虚拟主机:虚拟两台主机ip为100,200, 对应访问目录:/www/ip/100, /www/ip/200并创建首页文件index.html
[root@rhcsa ~]# cd /var/www/html
[root@rhcsa html]# nmcli c modify ens160 +ipv4.addresses 192.168.255.200/24
[root@rhcsa html]# nmcli c modify ens160 +ipv4.addresses 192.168.255.100/24
[root@rhcsa html]# nmcli c up ens160
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@rhcsa html]# mkdir /www/ip/{100,200} -p
[root@rhcsa html]# ls -l /www/ip/
total 0
drwxr-xr-x. 2 root root 6 Jul 26 14:16 100
drwxr-xr-x. 2 root root 6 Jul 26 14:16 200
[root@rhcsa html]# echo "This is page for 100" > /www/ip/100/index.html
[root@rhcsa html]# echo "This is page for 200" > /www/ip/200/index.html
[root@rhcsa html]# cd /etc/httpd/conf.d/
[root@rhcsa conf.d]# vim myhosts.conf
[root@rhcsa conf.d]# systemctl restart httpd
[root@rhcsa conf.d]# vim myhosts.conf
修改文件:
<Directory "/www/ip">
AllowOverride None
Require all granted
</Directory>
<VirtualHost 192.168.255.100:80>
DocumentRoot "/www/ip/100"
</VirtualHost>
<VirtualHost 192.168.255.200:80>
DocumentRoot "/www/ip/200"
</VirtualHost>
[root@rhcsa conf.d]# getenforce Enforcing
Enforcing
[root@rhcsa conf.d]# setenforce 0
[root@rhcsa conf.d]# systemctl restart httpd
配置不同端口的虚拟主机访问apache服务器
[root@rhcsa html]# mkdir /www/ip/{9090,9091} -p
[root@rhcsa html]# echo "This is page for 9090" > /www/ip/9090/index.html
[root@rhcsa html]# echo "This is page for 9091" > /www/ip/9091/index.html
[root@rhcsa html]# cd /etc/httpd/conf.d/
[root@rhcsa conf.d]# vim myhosts.conf
#配置文件:
<Directory "/www/port">
AllowOverride None
Require all granted
</Directory>
Listen 9090
<VirtualHost 192.168.255.100:9090>
DocumentRoot "/www/port/9090"
ServerName 192.168.255.100
</VirtualHost>
Listen 9091
<VirtualHost 192.168.255.100:9091>
DocumentRoot "/www/port/9091"
ServerName 192.168.255.100
</VirtualHost>
[root@rhcsa conf.d]# systemctl restart httpd