我最近试图用Apache设置一个测试服务器.该网站必须在域www.mytest.com下运行.我总是犯403 Forbidden个错误.我使用的是Ubuntu 10.10服务器版.文档根目录在目录/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>

我的文档根目录中没有.htaccess个文件.权限设置正确(可由www数据读取).

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

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

我卡住了.有人能帮忙吗?

推荐答案

Apache2.4.3(或者稍早一点)添加了一个新的安全特性,这通常会导致此错误.您还会看到一条"客户端被服务器配置拒绝"形式的日志(log)消息.该功能要求用户身份才能访问目录.它在httpd中默认打开.Apache附带的配置文件.您可以通过指令看到功能的启用

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>

Linux相关问答推荐

是否可以在Bash正则表达式中排除?

在正在运行的进程的输出周围添加自定义字符串

/proc/mounts 没有像 /proc/self/mountinfo 这样的源信息

如何使用 sed 和 date 命令替换和格式化字符串中的日期?

Bash 更新 yaml 文件中的图像值

在 Ansible 中使用 JSON 查询过滤数据以从 ansible_fact 中提取数据

PHP factor 30 从 Linux 到 Windows 的性能差异

如何优雅地退出 X11 事件循环?

如何在非阻塞套接字上处理 OpenSSL SSL_ERROR_WANT_READ / WANT_WRITE

PuTTY:更改默认 SSH 登录目录

我想为 Linux 内核做贡献

与交换空间相关的链接器性能?

polkitd未注册身份验证代理的解释

比较linux中两个未排序的列表,列出第二个文件中的唯一性

如何搜索文件并将它们压缩到一个 zip 文件中

GNU Octave 方法对矩阵中的每个项目进行操作.octave arrayfun(...)示例

如何安装python开发者包?

基于shell中正则表达式的 colored颜色 突出显示输出

Linux:处理成服务

Bash 将 awk 的输出捕获到数组中