Apache Permission denied for/srv/www : unable to check . htaccess 文件但不是/var/www

标签 apache .htaccess srv

我在 Centos 6.5 上遇到了一个问题:

[Mon Dec 28 12:10:52 2012] [a] [client 127.0.0.1] (13) Permission denied:/srv/www/website/.htaccess pcfg_openfile: 无法检查 htaccess 文件,确保它是可读的

基本上,我正在构建一个全新的服务器并尝试将我所有的网站迁移到/srv/www 文件夹而不是/var/www,因为它似乎是 future 的标准(有一个关于它的完整讨论所以只需谷歌)。

我做了什么:

1) 添加了一个新组(groupadd developers)

2) 添加用户 a (gid 501), root, apache, nobody 到上面的组 (usermod -G develoeprs a && usermod -G develoeprs apache && usermod -G develoeprs root && usermod -G develoeprs nobody)

3) 将所有文件夹和文件复制到/srv/www

4) 将整个/srv/www 的所有权更改为 apache:developers (chown -R apache:developers/srv/www)

5) 更改模式,使/srv/www 组可读/可写/可搜索 (chmod -R 2775/srv/www)

6) 在/etc/sysconfig/httpd 的末尾添加 'umask 002' 以便它以组可写模式运行

7) 添加虚拟主机到/etc/httpd/conf.d/vhosts.conf(服务 httpd configtest 抛出 OK)

NameVirtualHost *:80
NameVirtualHost *:443

SSLStrictSNIVHostCheck off

<VirtualHost *:443>
    ServerAdmin webmaster@domain.ext
    DocumentRoot /srv/www/test
    ServerName test.domain.com
    ServerAlias test.domain
    SSLEngine on
    SSLCertificateFile /etc/httpd/certs/domain.com/server.crt
    SSLCertificateKeyFile /etc/httpd/certs/domain.com/server.key
    <Directory /srv/www/test>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

8) 重启服务器 9) 手动启动httpd,因为它要求SSL证书密码,否则自动启动失败(需要研究如何在重启后自动启动它)

我仍然收到与上述相同的错误消息。

然后,我尝试将 apache 用户的/etc/passwd 中的主文件夹更改为/srv/www(服务器重启),但仍然没有成功,即权限被拒绝。我什至重命名了旧的/var/www 文件夹,并在/var/www 中创建了一个符号链接(symbolic link)到/srv/www。另一种尝试是将 chown 返回到 root:root、apache:apache 和 :developers group。

/srv/www/[不工作]

drwxr-xr-x。 2 root root (cgi-bin, error, html, icons)

drwxrwsr-x。 5 个 Apache 开发人员(所有其他网站文件夹)

-rwxrwsr-x。 1 位 Apache 开发人员(所有文件)

/服务/

drwxrwsr-x。 4 个 Apache 开发人员 www

/var/www [工作中]

drwxr-xr-x。 2 root root (cgi-bin, error, html, icons)

drwxrwxr-x。 3 个 Apache 开发人员(所有其他网站文件夹)

-rwxrwxr-x。 1名apache开发人员(所有网站文件)

然后,只要我将我网站的一个文件夹复制到/var/www 并在/etc/httpd/conf.d/vhosts.conf 中指向路径,它就会开始正常工作!

有谁知道为什么它在/SRV/WWW 文件夹中不起作用??

最佳答案

我终于找到了问题的根源。这是由于 SELinux 策略覆盖了基本的传统自主访问控制 (DAC) 方法,例如通常用于控制用户文件访问的文件权限或访问控制列表 (ACL)!

$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

$ setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]

$ setenforce Permissive

$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

有关 SELinux 的更多信息,请访问 Centos .一旦我切换到 Permissive 模式,我的/srv/就开始工作了。

如果您知道这样做的目的和原因,那么您可以通过更改以下行在/etc/selinux/config 中永久禁用 SELinux:

SELINUX=enforcing

SELINUX=disabled

重新启动您的服务器,您应该将其永久禁用。

Note: When switching from Disabled to either Permissive or Enforcing mode, it is highly recommended that the system be rebooted and the filesystem relabeled.

关于Apache Permission denied for/srv/www : unable to check . htaccess 文件但不是/var/www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21233552/

相关文章:

mod-rewrite - 在 apache 2.2.3 上设置通配符子域(使用反向代理)

apache - htaccess 不能正常工作

HTML5离线数据存储

.htaccess - 如何在 Opencart 中将所有 www 重定向到非 www 和 SSL Url?

java - Consul Java DNS SRV 查找

php - 非动态自定义HTTP header

php - 为什么 index.html 优先于 index.php?

apache - Apache日志-%a和%h有什么区别?

java - JNDI 是否使用 DNS 搜索列表?