Apache VirtualHost 403 禁止
我最近尝试使用 Apache 设置测试服务器。该站点必须在 www.mytest.com
域下运行。我总是收到 403 Forbidden
错误。我使用的是 Ubuntu 10.10 服务器版本。文档根目录位于 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
服务器上主机文件的内容(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
站点配置
<VirtualHost *>
ServerAdmin [email protected]
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-data 可读)。
如果我从桌面输入 IP 地址,该站点就会正确显示。我更改了桌面上的主机文件,将 www.mytest.com
指向服务器的 IP。当我使用它时,我得到403
。由于该网站的许多功能都对站点名敏感,因此我必须能够通过域名访问该站点。
另一个有趣的事情是,即使所有日志文件都正确创建,它们也没有有关此错误的信息。
我被困住了。有人可以帮忙吗?
I recently tried to set a test server up with Apache. The site must run under domain www.mytest.com
. I always get a 403 Forbidden
error. I am on Ubuntu 10.10 server edition. The doc root is under dir /var/www
. The following are my settings:
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 [email protected]
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>
I have no .htaccess
file in my doc root. The permissions are set correctly (readable by www-data).
If I type in the IP address from my desktop, the site shows up correctly. I changed the hosts file on my desktop to point www.mytest.com
to the server's IP. When I use it, I get 403
. Since many functions of this site are sitename-sensitive, I have to be able to access the site by the domain name.
Another funky thing is, even if all log files are created properly, they have no information regarding this error.
I am stuck. Can anybody help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
我在 Ubuntu 14.04 上的虚拟主机上遇到了同样的问题
对我来说,以下解决方案有效:
http:// /ubuntuforums.org/showthread.php?t=2185282
它只是添加一个
标签/etc/apache2/apache2.confI was having the same problem with a virtual host on Ubuntu 14.04
For me the following solution worked:
http://ubuntuforums.org/showthread.php?t=2185282
It's just adding a
<Directory >
tag to/etc/apache2/apache2.conf
我在 Arch Linux 上也遇到了这个问题......这花了我一些时间,但我很高兴现在我发现了我的错误:
我的帐户中包含
.html
文件的目录。我在
r+x
上设置了所有内容,但仍然收到403
错误。然后我完全返回并尝试将我的主目录设置为执行,这解决了我的问题。
I had this issue on Arch Linux too... it costs me some time but I'm happy now that I found my mistake:
My directory with the
.html
files where in my account.I set everything on
r+x
but I still got the403
error.Than I went completely back and tried to set my home-directory to execute which solved my problem.
可能是你没有安装PHP~!
It could be you haven't setup PHP~!
这适用于 Linux Fedora for VirtualHost:(Lampp/Xampp)
转到:/opt/lampp/etc/extra
打开:httpd-vhosts.conf
将其插入到 httpd-vhosts.conf 中
。 : 不要忘记评论前面的例子
已经存在于 httpd-vhosts.conf
设置你的主机系统文件:
转到:/etc/文件夹找到主机文件(/etc/hosts)
我插入这个:(但不确定是否100%)
- >打开或重新启动 Apache。
打开控制台并粘贴此命令以打开
XAMPP 图形界面:
sudo /opt/lampp/manager-linux-x64.run
注意:调整应用程序文件夹的路径,
例如:DocumentRoot "/home/USER/Desktop/My_Project"
并设置目录路径:
ex : 。 .. <目录“/home/USER/Desktop/My_Project”> ...
但这应该进行测试,评论是否有效...
附加说明:
本地化 Lampp 文件夹:(路径)
/opt/lampp
启动 Lampp :
sudo /opt/lampp/lampp 启动
根据需要调整权限:
sudo chmod o+w /opt/lampp/manager-linux-x64.run
主机文件路径:
/etc/hosts
This works on Linux Fedora for VirtualHost : ( Lampp/Xampp )
Go to : /opt/lampp/etc/extra
Open : httpd-vhosts.conf
Insert this in httpd-vhosts.conf
p.s. : Don't forget to comment the previous exemple
already present in httpd-vhosts.conf
Set your hosts system file :
Go to : /etc/ folder find hosts file ( /etc/hosts )
I insert this : (but not sure to 100% if this good)
-> Open or Restart Apache.
Open a console and paste this command for open a
XAMPP graphic interface :
sudo /opt/lampp/manager-linux-x64.run
Note : Adjust path how you want to your app folder
ex: DocumentRoot "/home/USER/Desktop/My_Project"
and set directory path too :
ex : ... <Directory "/home/USER/Desktop/My_Project"> ...
But this should be tested, comment if this work ...
Additionnal notes :
Localisation Lampp folder : (Path)
/opt/lampp
Start Lampp :
sudo /opt/lampp/lampp start
Adjust rights if needed :
sudo chmod o+w /opt/lampp/manager-linux-x64.run
Path to hosts file :
/etc/hosts
时遇到了同样的问题
。我们需要 /var/www/html/path/to/index 中的index.php或index.html。
I was having the same problem with apache2.4
We need a index.php or index.html in /var/www/html/path/to/index.
问题是文件访问权限错误。
我更改了目录的权限并且它起作用了。
The problem was that the file access permission was wrong.
I changed the permissions of the directory and it worked.
我刚刚在这个愚蠢的问题上花了几个小时
首先,在终端中使用它更改权限
我不知道 664 和 775 之间有什么区别
我像这样做了两个 775
另外 htdocs 需要目录路径,例如对我来说
这是另一件愚蠢的事情,
请确保您的图像 src 链接是您的域名,例如
确保
您在终端中使用 pico 编辑那些
我还为图像创建了一个目录具体来说,当您在浏览器地址栏输入domainname.com/images时,您将获得可以下载的照片列表,需要下载成功才能指示图像文件正常工作
这些是我尝试过的解决方案,现在我有了正常运行的图像... 耶!!!
讨论下一个问题
I just spent several hours on this stupid problem
First, change permissions using this in terminal
I don't know what the difference is between 664 and 775
I did both 775 like this
Also htdocs needs the directory path for instance for me it was
This is the other dumb thing too
make sure that your image src link is your domain name for instance
Be sure to have
You edit those using pico in terminal
I also created a directory for images specifically so that when you type in the browser address bar domainname.com/images, you will get a list of photos which can be downloaded and need to be downloaded successfully to indicate image files that are working properly
And those are the solutions I have tried, now I have functioning images... yay!!!
Onto the next problem(s)
Apache 2.4.3(或者可能稍早一些)添加了一个新的安全功能,该功能通常会导致此错误。您还会看到“客户端被服务器配置拒绝”形式的日志消息。该功能需要用户身份才能访问目录。它在 Apache 附带的 httpd.conf 中默认打开。您可以使用指令查看该功能的启用情况,
这基本上是说拒绝所有用户的访问。要解决此问题,请删除拒绝的指令(或更好)将以下指令添加到您想要授予访问权限的目录:
如
Apache 2.4.3 (or maybe slightly earlier) added a new security feature that often results in this error. You would also see a log message of the form "client denied by server configuration". The feature is requiring a user identity to access a directory. It is turned on by DEFAULT in the httpd.conf that ships with Apache. You can see the enabling of the feature with the directive
This basically says to deny access to all users. To fix this problem, either remove the denied directive (or much better) add the following directive to the directories you want to grant access to:
as in
对于apache Ubuntu 2.4.7,我终于发现你需要在apache2.conf中将虚拟主机列入白名单
For apache Ubuntu 2.4.7 , I finally found you need to white list your virtual host in apache2.conf
这可能是权限问题。
根据 读取、写入和执行此页面有关 Apache 403 错误。
由于您使用的是
Allow from all
,因此您的顺序并不重要,但您可以尝试将其切换为Deny,Allow
以设置 默认行为 为“允许”。This may be a permissions problem.
according to this page about Apache 403 errors.
Since you're using
Allow from all
, your order shouldn't matter, but you might try switching it toDeny,Allow
to set the default behavior to "allowing."将 Directory 子句移出虚拟主机,并将其放在声明虚拟主机之前。
也让我抓狂了很长一段时间。不知道为什么。这是 Debian 的事情。
Move the Directory clause out of the virtualhost, and put it before declaring the virtualhost.
Drove me nuts for a long time too. Don't know why. It's a Debian thing.
如果你做的一切正确,只需授予主目录权限,例如:
然后
If you did everything right, just give the permission home directory like:
then