我目前正在运行Centos 7并启用SELinux,目前我在/ home / user / public_html下配置我的apache docroot,文件/文件夹显示上下文标签:
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 readme.html
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-activate.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-admin
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-blog-header.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-comments-post.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-config-sample.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-content
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-cron.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-includes
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-links-opml.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-load.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-login.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-mail.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-settings.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-signup.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-trackback.php
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 xmlrpc.php
我希望以递归方式将当前上下文标签httpd_user_content_t
分配并更改为httpd_user_script_exec_t
,并仅应用于public_html /下的所有.php文件类型。我已经尝试了下面的代码,但上下文仍未改变:
# sudo semanage fcontext -a -t httpd_user_script_exec_t "/home/user/public_html/.*\.php"
# sudo restorecon -Rv public_html
# ls -Z
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 readme.html
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-activate.php
drwxrwxr-x. user apache system_u:object_r:httpd_user_content_t:s0 wp-admin
-rw-r--r--. user apache system_u:object_r:httpd_user_content_t:s0 wp-blog-header.php
答案 0 :(得分:1)
我认为您没有告诉SELinux您要使用正则表达式的括号。像这样尝试:
sudo semanage fcontext -a -t httpd_user_script_exec_t "/home/user/public_html/(.*\.php)"