selinux造成虚拟目录文件无法访问

一.输入网站页面文件,显示无权限访问。

日志中查看显示没有权限

 AH00035: access to /index.html denied (filesystem path '/home/www/test/index.html') because search permissions are missing on a component of

1.可以直接关闭就好了
setenforce 0 关闭 selinux
setenforce 1 打开 selinux


2.用命令 restorecon 可以用来恢复文件默认的上下文:

restorecon -R -v /var/www/html/index.html  //-R 表示递归,如果是目录,则该目录下的所有子目录、文件都会得到修复  
命令 chcon 可以改变文件的上下文信息,通常我们使用一个参照文件来进行修改:

chcon --reference=/var/www/html/index.html /var/www/html/test.html


二.修改后可以访问但PHP 无法创建文件:
file_put_contents("success.txt","2222", FILE_APPEND);
无法写入创建文件

1.执行命令setenforce 0临时关闭selinux可写入成功

输入命令打开这两条权限
setsebool -P httpd_unified on

setsebool -P httpd_enable_cgi on


三.其他
getsebool -a                                  #列出所有模块
getsebool -a | grep httpd                       #列出所有与hpptd相关的模块

selinux默认不允许httpd访问“/home/用户名”目录(但是允许访问"/usr/local/用户名"这种目录),现在有两种解决方案:

允许用户httpd访问其家目录

setsebool -P httpd_read_user_content 1
setsebool -P httpd_enable_homedirs 1

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

setsebool -P allow_ftpd_anon_write=1          #允许ftpd匿名用户可写
setsebool -P ftp_home_dir 1                   #允许用户访问自己的根目录
setsebool -P ftpd_is_daemon 1                 #允许daemon运行ftpd
setsebool -P ftpd_disable_trans 1             #关闭SELINUX对ftpd的保护
setsebool -P allow_httpd_anon_write=1         #允许httpd匿名用户可写
setsebool -P allow_httpd_sys__anon_write=1    #同上
setsebool -P httpd_enable_cgi 1               #httpd被设置允许cgi被执行
setsebool -P httpd_enable_homedirs 1          #允许访问用户的根目录
setsebool -P httpd_tty_comm 1                 #允许httpd控制终端
setsebool -P httpd_unified 0                  #httpd之间相互独立
setsebool -P httpd_builtin_ing 0              #同httpd环境一样运行
setsebool -P httpd_can_network_connect_db 1   #httpd可以连接到数据库(如连接mysql就必须设置)
setsebool -P httpd_can_network_connect 1      #httpd可以连接到网络(如连接redis就必须设置)
setsebool -P httpd_read_user_content 1        #开启用户文件的访问权限(如日志文件就必须设置)
setsebool -P httpd_suexec_disable_trans 1     #禁用suexec过度
setsebool -P httpd_disable_trans 1            #允许daemon用户启动httpd
setsebool -P httpd_can_sendmail 1             #允许httpd发送email
setsebool -P named_write_master_zones 1       #允许修改dns的主zone文件
setsebool -P named_disable_trans 1            #允许daemon启动named
setsebool -P nfs_export_all_ro 1              #nfs只读
setsebool -P nfs_export_all_rw 1              #nfs可读写
setsebool -P use_nfs_home_dirs 1              #允许本机访问远程nfs的根目录
setsebool -P allow_smbd_anon_write=1          #samba允许匿名用户可写
setsebool -P samba_enable_home_dirs 1         #允许根目录访问
setsebool -P use_samba_home_dirs 1            #允许本机访问远程samba根目录
setsebool -P smbd_disable_trans 1             #允许daemon启动samba
setsebool -P allow_rsync_anon_write=1         #允许匿名用户可写
setsebool -P rsync_disable_trans 1            #允许daemon启动rsync
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值