[root@kvm5 ~]# vim /etc/httpd/conf/httpd.conf <Directory /> AllowOverride none Require all granted </Directory>
[root@kvm5 ~]# grep ' Alias' /etc/httpd/conf/httpd.conf # Alias: Maps web paths into filesystem paths and is used to # Alias /webpath /full/filesystem/path Alias /web /mnt/www # ScriptAliases are essentially the same as Aliases, except that # directives as to Alias.
[root@kvm5 ~]# systemctl reload httpd.service
[root@kvm5 ~]# mkdir /mnt/www [root@kvm5 ~]# echo 'abc' > /mnt/www/c.html
[root@kvm5 ~]# setenforce 1
[root@kvm5 ~]# getenforce Enforcing
[root@kvm5 ~]# vim /etc/selinux/config [root@kvm5 ~]# grep enforcing /etc/selinux/config # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. SELINUX=enforcing
[root@kvm5 ~]# curl -s http://kvm5.deyu.wang/web/c.html <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /web/c.html on this server.</p> </body></html>
mnt_t
,而不是 httpd_sys_content_t
。
[root@kvm5 ~]# ll -Z /var/www/html /mnt/www /mnt/www: -rw-r--r--. root root unconfined_u:object_r:mnt_t:s0 c.html /var/www/html: -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 inx -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 missing.html
httpd_sys_content_t
。
[root@kvm5 ~]# chcon -Rv -t httpd_sys_content_t /mnt/www changing security context of ‘/mnt/www/c.html’ changing security context of ‘/mnt/www’
[root@kvm5 ~]# curl -s http://kvm5.deyu.wang/web/c.html abc
[root@kvm5 ~]# vim /etc/httpd/conf/httpd.conf <Directory /> AllowOverride none Require all denied </Directory>
[root@kvm5 ~]# systemctl reload httpd.service
[root@kvm5 ~]# curl -s http://kvm5.deyu.wang/web/c.html | sed -e 's/<[^>]*>//g' -e '/^$/d' [root@kvm5 ~]# curl -s http://kvm5.deyu.wang/web/c.html 403 Forbidden Forbidden You don't have permission to access /web/c.html on this server.