示例一
需求:本例要求为 http://server0.example.com 配置Web站点,要求如下:
1.从http://ldap.example.com/pub/example.html下载一个主页文件,将其重命名为 index.html
2.将此文件拷贝到站点的 DocumentRoot 目录下,不要对文件 index.html 的内容作任何修改
3.来自my133t.org的客户端的访问会被拒绝
[root@system1 Desktop]# yum -y install httpd
[root@system1 Desktop]# cd /var/www/html
[root@system1 html]# ls
[root@system1 html]# wget http://ldap.example.com/pub/example.html
[root@system1 html]# mv example.html index.html
[root@system1 html]# ls
index.html
[root@system1 html]# cat index.html
server30.example.com
[root@system1 html]# systemctl start httpd
[root@system1 html]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@system1 html]# cd
[root@system1 ~]# systemctl mask iptables.service ebtables.service
ln -s '/dev/null' '/etc/systemd/system/iptables.service'
ln -s '/dev/null' '/etc/systemd/system/ebtables.service'
[root@system1 ~]# systemctl stop iptables.service ebtables.service
[root@system1 ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.16.30.0/24 service name=http accept' --permanent
success
[root@system1 ~]# firewall-cmd --reload
success
验证
在火狐浏览器上验证
示例二
需求为站点 http://server0.example.com 配置TLS加密需求如下
1.一个已签名证书从以下地址获取 http://classroom.example.com/pub/server30.crt
2.此证书的密钥从以下地址获取 http://lclassroom.example.com/pub/server30.key
3.此证书的签名授权信息从以下地址获取http://classroom.example.com/pub/group30.crt
2.2方案步骤
[root@system1 ~]# yum -y install mod_ssl
[root@system1 ~]# cd /etc/httpd/
[root@system1 httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@system1 httpd]# cd conf.d
[root@system1 conf.d]# ls
autoindex.conf README ssl.conf userdir.conf welcome.conf
[root@system1 conf.d]# vim ssl.conf
[root@system1 conf.d]# cd /etc/pki/tls/certs
[root@system1 certs]# ls
ca-bundle.crt localhost.crt Makefile
ca-bundle.trust.crt make-dummy-cert renew-dummy-cert
[root@system1 certs]# wget http://ldap.example.com/pub/server30.crt
[root@system1 certs]# ls
ca-bundle.crt localhost.crt Makefile server30.crt
ca-bundle.trust.crt make-dummy-cert renew-dummy-cert
[root@system1 certs]# wget http://ldap.example.com/pub/group30.crt
[root@system1 certs]# ls
ca-bundle.crt localhost.crt renew-dummy-cert
ca-bundle.trust.crt make-dummy-cert server30.crt
group30.crt Makefile
[root@system1 certs]# cd ../private
[root@system1 private]# wget http://ldap.example.com/pub/server30.key
[root@system1 private]# ls
localhost.key server30.key
[root@system1 private]# vim /etc/httpd//conf.d/ssl.conf
[root@system1 private]# systemctl restart httpd
[root@system1 private]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.16.30.0/24 service name=https accept' --permanent
success
[root@system1 private]# firewall-cmd --reload
success
验证
示例三
[root@system1 private]# cd /var/www/html
[root@system1 html]# ls
index.html
[root@system1 html]# cd /var/www
[root@system1 www]# mkdir virtual
[root@system1 www]# wget -O virtual/index.html http://ldap.example.com/pub/www.html
[root@system1 www]# cat virtual/index.html
www.example.com
[root@system1 www]# chown -R apache.apache /var/www/
[root@system1 www]# useradd floyd
[root@system1 www]# setfacl -m u:floyd:rwx virtual/
[root@system1 www]# cd
[root@system1 ~]# cd /etc/htttpd/conf.d
bash: cd: /etc/htttpd/conf.d: No such file or directory
[root@system1 ~]# cd /etc/httpd/conf.d
[root@system1 conf.d]# find / -name *vhost*
/dev/vhost-net
/etc/selinux/targeted/modules/active/modules/vhostmd.pp
/usr/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/vhost
/usr/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/vhost/vhost_net.ko
/usr/lib64/httpd/modules/mod_vhost_alias.so
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
[root@system1 conf.d]# cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf .
[root@system1 conf.d]# vim httpd-vhosts.conf
[root@system1 conf.d]# systemctl restart httpd.service
[root@system1 conf.d]# cd /var/www/html
[root@system1 html]# mkdir private
[root@system1 html]# wget -O private/index.html http://ldap.example.com/pub/private.html
[root@system1 html]# ls private/
index.html
[root@system1 html]# vim /etc/httpd/conf.d/httpd-vhosts.conf
[root@system1 html]# systemctl restart httpd
验证
示例四
[root@system1 ~]#cd /var/www/html/
[root@system1 html]#mkdir private
[root@system1 html]#wget -O private/index.html http://classroom.example.com/pub/private.html
[root@system1 html]#ls
index.html
[root@system1 html]#cat private/index.html
private
[root@system1 html]#vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName server0.example.com
<Directory "/var/www/html/private">
Require ip 172.16.30.130
<Directory>
<VirtualHost >
[root@system1 html]#systemctl resart httpd
//在客户端:
[root@system2]#firefox &
//客户端不能登陆
在服务端的浏览器上能登陆
验证
示例五
[root@system1 ~]#cd /var/www/
[root@system1 www]#mkdir wsgi
[root@system1 www]#wget -O wsgi/webapp.wsgi http://ldap.example.com/pub/webapp.wsgi
[root@system1 www]#chown -R apache.apache wsgi/
[root@system1 www]#vim /etc/httpd/conf.d/httpd-vhosts.conf
在最后添加
Listen 8909
<VirtualHost *:8909>
WSGIScripAlias / "/var/www/wsgi/webapp.wsgi"
ServerName alt.example.com
</virtualHosts>
[root@system1 www]#yum -y mod_wsgi*
[root@system1 ~]#systemctl stop httpd
[root@system1 ~]#systemctl start httpd
[root@system1 ~]#semanage port -a
-t http_port_t -p tcp 8909
[root@system1 ~]#semanage port -l|grep http
[root@system1 ~]#firewall-cmd --add-rich-rule 'rule family=ipv4 source address=172.25.0.0/24 port protocol=tcp port=8909 accept' --permanent
[root@system1 ~]#firewall-cmd --reload
在客户端:
[root@system2 ~]vim /etc/hosts
172.16.30.130 alt.example.com
[root@system2 ~]firefox &
验证