首页 文章

Apache VirtualHost 403 Forbidden

提问于
浏览
106

我最近尝试用Apache设置测试服务器 . 该网站必须在域 www.mytest.com 下运行 . 我总是得到 403 Forbidden 错误 . 我在Ubuntu 10.10服务器版上 . doc根目录在dir /var/www 下 . 以下是我的设置:

Content of /var/www

ls -l /var/www/

total 12
drwxr-xr-x 2 root root 4096 2011-08-04 11:26 mytest.com
-rwxr-xr-x 1 root root 177 2011-07-25 16:10 index.html

Content of the host file on the server (with IP 192.168.2.5)

cat /etc/hosts

127.0.0.1 localhost 
127.0.1.1 americano
192.168.2.5 americano.mytest.com www.mytest.com

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Site config

<VirtualHost *>
ServerAdmin admin@mytest.com
ServerName www.mytest.com
ServerAlias mytest.com

DocumentRoot "/var/www/mytest.com"

ErrorLog /var/log/apache2/mytest-error_log
CustomLog /var/log/apache2/mytest-access_log combined

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/mytest.com">
Options -Indexes FollowSymLinks
AllowOverride None

Order allow,deny
Allow from all
</Directory>
</VirtualHost>

我的doc根目录中没有 .htaccess 文件 . 权限设置正确(可通过www-data读取) .

如果我从桌面输入IP地址,则网站会正确显示 . 我更改了桌面上的hosts文件,将 www.mytest.com 指向服务器的IP . 当我使用它时,我得到 403 . 由于此站点的许多功能都是网站名称敏感的,我必须能够通过域名访问该站点 .

另一个时髦的事情是,即使所有日志文件都正确创建,它们也没有关于此错误的信息 .

我被卡住了 . 有人可以帮忙吗?

8 回答

  • 5

    Apache 2.4.3(或稍早一点)添加了一个新的安全功能,通常会导致此错误 . 您还会看到“客户端拒绝服务器配置”形式的日志消息 . 该功能要求用户身份访问目录 . 它由Apache附带的httpd.conf中的DEFAULT打开 . 您可以使用该指令查看功能的启用

    Require all denied
    

    这基本上就是拒绝所有用户访问 . 要解决此问题,请删除denied指令(或更好)将以下指令添加到要授予其访问权限的目录中:

    Require all granted
    

    如在

    <Directory "your directory here">
       Order allow,deny
       Allow from all
       # New directive needed in Apache 2.4.3: 
       Require all granted
    </Directory>
    
  • 8

    对于apache Ubuntu 2.4.7,我终于发现你需要在apache2.conf中列出你的虚拟主机

    # access here, or in any related virtual host.
    <Directory /home/gav/public_html/>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
    
  • 266

    这可能是权限问题 .

    Web服务器httpd用户必须是可读,可写和可执行的虚拟文档根目录的每个父路径

    根据this page关于Apache 403的错误 .

    由于您使用的是 Allow from all ,因此您的订单无关紧要,但您可以尝试将其切换为 Deny,Allow 以将default behavior设置为"allowing."

  • 0

    将Directory子句移出虚拟主机,并在声明虚拟主机之前将其放入 .

    很长一段时间也让我疯了 . 不知道为什么 . 这是Debian的事情 .

  • 11

    我只花了几个小时来解决这个愚蠢的问题

    首先,在终端中使用此更改权限

    find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
    

    我不知道664和775之间的区别是什么我做了775这样的同样htdocs需要目录路径,例如对我来说它是

    /usr/local/apache2/htdocs 
    
    find htdocs -type f -exec chmod 775 {} + -o -type d -exec chmod 775 {} +
    

    这也是另一个愚蠢的事情

    例如,确保您的图像src链接是您的域名

    src="http://www.fakedomain.com/images/photo.png"
    

    一定要有

    EnableSendfile off in httpd.conf file
    EnableMMAP off in httpd.conf file
    

    您可以在终端中使用pico编辑它们

    我还专门为图像创建了一个目录,这样当您在浏览器地址栏中输入domainname.com/images时,您将获得一张可以下载并需要成功下载的照片列表,以指示正常工作的图像文件

    <Directory /usr/local/apache2/htdocs/images>
    AddType images/png .png
    </Directory>
    

    这些是我尝试过的解决方案,现在我已经有了正常运行的图像......耶!

    在下一个问题上

  • 0

    我在Ubuntu 14.04上遇到了与虚拟主机相同的问题

    对我来说,以下解决方案有效:

    http://ubuntuforums.org/showthread.php?t=2185282

    它只是将 <Directory > 标签添加到 /etc/apache2/apache2.conf

  • 0

    如果你做的一切正确,只需给出权限主目录,如:

    sudo chmod o+x $HOME
    

    然后

    sudo systemctl restart apache2
    
  • 0

    问题是文件访问权限是错误的 .

    我更改了目录的权限,并且工作正常 .

相关问题