1:配置yum源,下载并安装httpd
[root@localhost ~]# vim /etc/yum.repos.d/rhel_dvd.repo
[root@localhost ~]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel_dvd
Cleaning up everything
[root@localhost ~]#
[root@localhost ~]# hostnamectl set-hostname apache-server.example.com
[root@localhost ~]# hostname
apache-server.example.com
[root@localhost ~]# yum install httpd -y
Loaded plugins: langpacks
rhel_dvd | 4.1 kB 00:00
(1/2): rhel_dvd/group_gz | 134 kB 00:00
(2/2): rhel_dvd/primary_db | 3.4 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.6-17.el7 rhel_dvd 1.2 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 rhel_dvd 103 k
apr-util x86_64 1.5.2-6.el7 rhel_dvd 92 k
httpd-tools x86_64 2.4.6-17.el7 rhel_dvd 77 k
mailcap noarch 2.1.41-2.el7 rhel_dvd 31 k
Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 1.5 M
Installed size: 4.3 M
Downloading packages:
(1/5): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00
(3/5): httpd-tools-2.4.6-17.el7.x86_64.rpm | 77 kB 00:00
(4/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00
(5/5): httpd-2.4.6-17.el7.x86_64.rpm | 1.2 MB 00:00
--------------------------------------------------------------------------------
Total 11 MB/s | 1.5 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-17.el7.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-17.el7.x86_64 5/5
Verifying : mailcap-2.1.41-2.el7.noarch 1/5
Verifying : httpd-tools-2.4.6-17.el7.x86_64 2/5
Verifying : apr-1.4.8-3.el7.x86_64 3/5
Verifying : apr-util-1.5.2-6.el7.x86_64 4/5
Verifying : httpd-2.4.6-17.el7.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-17.el7
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-17.el7 mailcap.noarch 0:2.1.41-2.el7
Complete!
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@localhost html]# systemctl stop firewalld.service
查看网页
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
查看配置文件
[root@localhost ~]# cd /var/www/html
[root@localhost html]# ls
[root@localhost html]# vim index.html
[root@localhost html]# systemctl restart httpd
编辑文件,可以在网页上显示
测试
2:改变index.html为westos
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
[root@localhost html]# vim westos
[root@localhost html]# systemctl restart httpd
清理上次实验痕迹
[root@localhost html]# rm -fr westos
[root@localhost html]# ls
index.html
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
[root@localhost html]# systemctl restart httpd
3:改变发布目录
[root@localhost html]# mkdir /westos/html -p ##建立发布目录
[root@localhost html]# vim /westos/html/index.html ##编辑发布目录内容
[root@localhost html]# vim /etc/httpd/conf/httpd.conf ##修改配置中发布目录指向
[root@localhost html]# systemctl restart httpd
[root@apache-server ~]# ls -lZd /var/www/html ##查看原来发布目录标签
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
[root@apache-server html]# ls -lZd /westos/ ##查看westos标签
drwxr-xr-x. root root system_u:object_r:default_t:s0 /westos/
[root@apache-server html]# semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?' ##修改westos标签
[root@apache-server html]# restorecon -FvvR /westos/ #刷新
restorecon reset /westos context system_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /westos/html context system_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /westos/html/index.html context system_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
测试
[root@apache-server html]# vim /etc/httpd/conf/httpd.conf
[root@apache-server html]# systemctl restart httpd
4:设置访问黑白名单
[root@apache-server html]# vim /etc/httpd/conf/httpd.conf
[root@apache-server html]# systemctl restart httpd
测试
5:设置密码
[root@apache-server html]# cd /etc/httpd/conf
[root@apache-server conf]# ls
httpd.conf magic
[root@apache-server conf]# htpasswd -cm authfile admin ##创建密码用户(第一次加c)
New password:
Re-type new password:
Adding password for user admin
[root@apache-server conf]# cat authfile
admin:apr1RmiemSwbpKam34LqYfabEZeuN9j1I0
[root@apache-server conf]# htpasswd -m authfile admin1
New password:
Re-type new password:
Adding password for user admin1
[root@apache-server conf]# cat authfile[root@apache-server html]# cd /etc/httpd/conf
[root@apache-server conf]# ls
httpd.conf magic
[root@apache-server conf]# htpasswd -cm authfile admin ##创建密码用户(第一次加c)
New password:
Re-type new password:
Adding password for user admin
[root@apache-server conf]# cat authfile
admin:apr1RmiemSwbpKam34LqYfabEZeuN9j1I0
[root@apache-server conf]# htpasswd -m authfile admin1
New password:
Re-type new password:
Adding password for user admin1
[root@apache-server conf]# cat authfilein:apr1RmiemSwbpKam34LqYfabEZeuN9j1I0admin1:apr186vnNA8pXcHGCST0LIc9vxg5yQ5xw.
[root@apache-server conf]# vim /etc/httpd/conf/httpd.conf
[root@apache-server conf]# systemctl restart httpd
6:多域名解析
建立文件
[root@apache-server conf]# mkdir /var/www/westos/news.westos.com -p
[root@apache-server conf]# mkdir /var/www/westos/gongyi.westos.com -p
[root@apache-server conf]# vim /var/www/westos/news.westos.com/index.html
[root@apache-server conf]# vim /var/www/westos/gongyi.westos.com/index.html
[root@apache-server conf]# cd /etc/httpd/conf.d/
[root@apache-server conf.d]# ls
autoindex.conf README userdir.conf welcome.conf
[root@apache-server conf.d]# vim default.conf ##编辑www配置文件
[root@apache-server conf.d]# vim news.conf ##编辑news配置文件
[root@apache-server conf.d]# cp news.conf gongyi.conf ##编辑gongyi配置文件
[root@apache-server conf.d]# systemctl restart httpd
测试
[root@foundation11 ~]# ping www.westos.com
PING www.westos.com (172.25.254.111) 56(84) bytes of data.
64 bytes from www.westos.com (172.25.254.111): icmp_seq=1 ttl=64 time=0.143 ms
64 bytes from www.westos.com (172.25.254.111): icmp_seq=2 ttl=64 time=0.154 ms
^C
--- www.westos.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.143/0.148/0.154/0.013 ms
[root@foundation11 ~]# ping news.westos.com
PING www.westos.com (172.25.254.111) 56(84) bytes of data.
64 bytes from www.westos.com (172.25.254.111): icmp_seq=1 ttl=64 time=0.196 ms
64 bytes from www.westos.com (172.25.254.111): icmp_seq=2 ttl=64 time=0.294 ms
^C
--- www.westos.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.196/0.245/0.294/0.049 ms
[root@foundation11 ~]# ping gongyi.westos.com
PING www.westos.com (172.25.254.111) 56(84) bytes of data.
64 bytes from www.westos.com (172.25.254.111): icmp_seq=1 ttl=64 time=0.132 ms
64 bytes from www.westos.com (172.25.254.111): icmp_seq=2 ttl=64 time=0.170 ms
^C
--- www.westos.com ping statistics ---