编程知识 cdmana.com

Linux中搭建静态网站(练习题)

在rhel8的系统上搭建网站:该网站ip地址主机位为11,设置documentroot为/www/你的名字拼音的缩写,网页内容为:my name is…

做题思路:

#面对这类的题目,确定好做题思路:
#配置题目要求的IP地址+关闭防火墙及SELinux+配置YUM源(选择其它方式也可)
#安装服务包(httpd)+按题目要求创建目录+编写网页内容+编写配置文件

配置题目要求的IP地址:

[[email protected] ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:e7:74:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.76.132/24 brd 192.168.76.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fee7:747a/64 scope link noprefixroute
       valid_lft forever preferred_lft forever


#没有题目所要求的IP地址
#配置IP地址:(可以增添一个网卡,也可以在原有的网卡上增加新的IP地址)
[[email protected] ~]# nmcli connection modify ens160 +ipv4.addresses 192.168.76.11/24		#增加新的IP地址
[[email protected] ~]# nmcli connection up ens160											#激活网卡
[[email protected] ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:e7:74:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.76.132/24 brd 192.168.76.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet 192.168.76.11/24 brd 192.168.76.255 scope global secondary noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fee7:747a/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

关闭防火墙及SELinux

[[email protected] ~]# systemctl stop firewalld.service		#关闭防火墙
[[email protected] ~]# setenforce 0							#关闭SELinux
[[email protected] ~]# systemctl status firewalld.service		#查看防火墙状态
[[email protected] ~]# getenforce								#查看SELinux状态

配置YUM源及安装服务包

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# cat local-csa.repo
[app-csa]
name=appstream
baseurl=file:///mnt/AppStream
gpgcheck=0

[base-csa]
name=base-csa
baseurl=file:///mnt/BaseOS
gpgcheck=0

[[email protected] ~]# mount /dev/sr0 /mnt/		#挂载
[[email protected] ~]# yum -y install httpd		#安装服务包

创建目录及编写网页内容

[[email protected] ~]# mkdir -pv  /www/jeff								#创建目录
[[email protected] ~]# echo "my name is jeff" > /www/jeff/index.html		#编写网页内容
[[email protected] ~]# tree /www
/www
└── jeff
    └── index.html

编写配置文件

[[email protected] conf.d]# cd /etc/httpd/conf.d
[[email protected] conf.d]# vim jeff.conf
#进入vim视图后,查找配置文件的模板
:sp /usr/share/doc/httpd/httpd-vhosts.conf
<VirtualHost *:80>
    ServerAdmin [email protected]-host2.example.com
    DocumentRoot "/var/www/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>

:sp ../conf/httpd.conf
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>


#具体配置如下:
<VirtualHost 192.168.76.11:80>
    ServerAdmin [email protected]-host2.example.com
    DocumentRoot "/www/jeff"
    ServerName 192.168.76.11
    ErrorLog "/var/log/httpd/jeff_error_log"
    CustomLog "/var/log/httpd/jeff_access_log" common
</VirtualHost>

<Directory "/www/jeff">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

[[email protected] conf.d]# httpd -t					#检查语法问题
[[email protected] conf.d]# systemctl restart httpd	#重启服务


#检验:
[[email protected] ~]# curl 192.168.76.11
my name is jeff

在这里插入图片描述

版权声明
本文为[Jeff657]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_56105279/article/details/127836785

Scroll to Top