Apache VirtualHost 403 Forbidden

Yuc*_*ang 116 linux apache ubuntu virtualhost http-status-code-403

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

/ 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
Run Code Online (Sandbox Code Playgroud)

服务器上主机文件的内容(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
Run Code Online (Sandbox Code Playgroud)

网站配置

<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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

小智 283

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

Require all denied
Run Code Online (Sandbox Code Playgroud)

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

Require all granted
Run Code Online (Sandbox Code Playgroud)

如在

<Directory "your directory here">
   Order allow,deny
   Allow from all
   # New directive needed in Apache 2.4.3: 
   Require all granted
</Directory>
Run Code Online (Sandbox Code Playgroud)

  • 我想请注意,如果您使用虚拟主机遇到此问题,则需要在apache/conf/extra/httpd-vhosts.conf文件中为每个虚拟主机设置添加"Require all granted". (3认同)

GAV*_*GAV 13

对于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>
Run Code Online (Sandbox Code Playgroud)


Pop*_*ops 8

这可能是权限问题.

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

根据这个页面关于Apache 403错误.

由于您正在使用Allow from all,您的订单无关紧要,但您可能会尝试将其切换Deny,Allow为将默认行为设置为"允许".

  • 可写?真?我不确定 (4认同)

sam*_*ler 5

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

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