繁体   English   中英

403 - Ubuntu 14.04上的权限被拒绝错误 - apache2

[英]403 - Permission denied error on Ubuntu 14.04 - apache2

这个问题已被多次询问,我已经完成了大部分解决方案,但仍然没有运气。

我正在尝试在新安装的Ubuntu 14.04 LTS版本上创建虚拟主机,由于某种原因我收到以下错误。

You don't have permission to access / on this server.

这就是我到目前为止所做的。

  1. /etc/apache2/sites-available/om.conf创建了以下虚拟主机

<VirtualHost *:80>
        ServerAdmin root@localhost
        ServerName  om.localhost.com
        ServerAlias www.om.localhost.com
        DocumentRoot "/home/jay/Projects/om/public"

        <Directory "/home/jay/Projects/om/public">
         Options Indexes FollowSymLinks
             Order allow,deny
             Allow from all
         AllowOverride All
         Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
  1. 使用以下命令启用主机

    sudo a2ensite om

  2. /etc/hosts添加了一个条目

127.0.0.1 localhost 127.0.1.1 Desk-PC-Ubuntu-14-02-LTS 127.0.0.1 om.localhost.com

  1. 使用以下命令设置项目目录的权限。

sudo chown -R www-data:www-data om sudo chmod -R 755 om

  1. 启用重写模块

    sudo a2enmod rewrite

  2. 重启apache2

sudo service apache2 restart

但我仍然得到同样的错误。

任何人都可以指出我做错了什么?

该项目基于Zend Framework 1.12并使用以下.htaccess文件。

SetEnv APPLICATION_ENV "development"
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

检查您在整个文件路径上的权限。 检查Projects文件夹并确保它是755 给它owner和一group www-data并不会有害。 如果您有任何.htaccess文件,请确保它们被分配644而不是755

您也在混合Apache版本指令。 由于您使用的是Ubuntu 14.04,因此您可能正在运行2.4。 所以你需要删除这些指令。

Order allow,deny
Allow from all

对于2.4,您只需要Require all granted

另外,我会添加一个DirectoryIndex指令,以确保它正在寻找索引文件。 如果它不识别一个,它将尝试列出目录并且索引关闭也将导致403禁止错误。 要求全部授予后,将其放入Directory标记中的vhost中。

DirectoryIndex index.php

在某些情况下,SELinux也是令人讨厌的并且也会导致许可问题。 如果所有其他方法都失败并且您启用了SELinux,则暂时禁用它以查看它是否修复了您的问题。

getenforce

这将告诉你它是否执行。

setenforce 0

这将设置为允许,然后您可以测试加载网站。 这将是暂时的,无法承受重启。 但是你可以使它永久化。

您可以使用chcon命令更改安全上下文。 例如

chcon -R --reference=/home/jay/Projects /home/jay/Projects/om/public

随时重新加载/重启apache以进行任何apache配置更改。 希望这里的内容有助于解决您的13权限被拒绝问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM