[root@kvm3 ~]# vim /etc/httpd/conf/httpd.conf [root@kvm3 ~]# grep alias_module -A35 /etc/httpd/conf/httpd.conf | egrep -v '(#|^$)' <IfModule alias_module> Alias /dyw "/mnt/www" ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" </IfModule>
[root@kvm3 ~]# grep '<Directory />' -A5 /etc/httpd/conf/httpd.conf | egrep -v '(#|^$)' <Directory /> AllowOverride none Require all granted </Directory>
[root@kvm3 ~]# vim /etc/httpd/conf/httpd.conf [root@kvm3 ~]# grep '<Directory />' -A10 /etc/httpd/conf/httpd.conf | egrep -v '(#|^$)' <Directory /> AllowOverride none Require all denied </Directory> <Directory /mnt/www> AllowOverride none Require all granted </Directory>
[root@kvm3 ~]# mkdir /mnt/www [root@kvm3 ~]# echo 'abc' > /mnt/www/c.html
[root@kvm3 ~]# systemctl restart httpd.service
[root@kvm3 ~]# curl -s http://kvm3.deyu.wang/dyw/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 /dyw/c.html on this server.</p> </body></html>
[root@kvm3 ~]# setenforce 0 [root@kvm3 ~]# curl -s http://kvm3.deyu.wang/dyw/c.html abc
mnt_t
,/var/www/html 目錄下的檔案 selinux content 為 httpd_sys_content_t
。
[root@kvm3 ~]# ll -Z /mnt/www/ -rw-r--r--. root root unconfined_u:object_r:mnt_t:s0 c.html [root@kvm3 ~]# ll -Z /var/www/html/ -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 aaa.html -rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 bbb.html drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 confidential -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 webapp.wsgi
httpd_sys_contetn_t
。
[root@kvm3 ~]# semanage fcontext -a -t httpd_sys_content_t "/mnt/www(/.*)?" [root@kvm3 ~]# restorecon -Rv /mnt/www restorecon reset /mnt/www/c.html context unconfined_u:object_r:mnt_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
[root@kvm3 ~]# setenforce 1 [root@kvm3 ~]# curl -s http://kvm3.deyu.wang/dyw/c.html abc