安装httpd并修改apache服务器的首页,虚拟主机,配置不同端口号的虚拟主机访问Apache服务器

安装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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_59138290

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值