Linux Apache VirtualHost 403 禁止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6959189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache VirtualHost 403 Forbidden
提问by Yuchen Wang
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:
我最近尝试使用 Apache 设置测试服务器。该站点必须在域下运行www.mytest.com
。我总是得到一个403 Forbidden
错误。我使用的是 Ubuntu 10.10 服务器版。文档根目录在 dir 下/var/www
。以下是我的设置:
Content of /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
Content of the host file on the server (with IP 192.168.2.5)
服务器上主机文件的内容(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).
.htaccess
我的文档根目录中没有文件。权限设置正确(可通过 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.
如果我从桌面输入 IP 地址,该站点就会正确显示。我将桌面上的主机文件更改为指向www.mytest.com
服务器的 IP。当我使用它时,我得到403
. 由于本站的很多功能都是对站点名称敏感的,所以我必须能够通过域名访问该站点。
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?
我被困住了。有人可以帮忙吗?
采纳答案by Phil L
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
Apache 2.4.3(或者可能稍早一些)添加了一个新的安全特性,这个特性经常会导致这个错误。您还会看到“客户端被服务器配置拒绝”形式的日志消息。该功能需要用户身份才能访问目录。它由 Apache 附带的 httpd.conf 中的 DEFAULT 开启。您可以使用指令查看该功能的启用情况
Require all denied
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:
这基本上是说拒绝所有用户的访问。要解决此问题,请删除 denied 指令(或更好),将以下指令添加到您要授予访问权限的目录中:
Require all granted
as in
如
<Directory "your directory here">
Order allow,deny
Allow from all
# New directive needed in Apache 2.4.3:
Require all granted
</Directory>
回答by Pops
This may be a permissions problem.
这可能是权限问题。
every single parent path to the virtual document root must be Readable, Writable, and Executable by the web server httpd user
虚拟文档根的每个父路径都必须是 Web 服务器 httpd 用户可读、可写和可执行的
according to this pageabout Apache 403 errors.
根据this pageabout Apache 403错误。
Since you're using Allow from all
, your order shouldn't matter, but you might try switching it to Deny,Allow
to set the default behaviorto "allowing."
由于您使用的是Allow from all
,因此您的顺序应该无关紧要,但您可以尝试将其切换为Deny,Allow
以将默认行为设置为“允许”。
回答by samtresler
Move the Directory clause out of the virtualhost, and put it before declaring the virtualhost.
将 Directory 子句移出虚拟主机,并将其放在声明虚拟主机之前。
Drove me nuts for a long time too. Don't know why. It's a Debian thing.
也让我抓狂了好久。不知道为什么。这是 Debian 的事情。
回答by Sebastian Viereck
The problem was that the file access permission was wrong.
问题是文件访问权限错误。
I changed the permissions of the directory and it worked.
我更改了目录的权限并且它起作用了。
回答by GAV
For apache Ubuntu 2.4.7 , I finally found you need to white list your virtual host in apache2.conf
对于 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>
回答by Jacob David C. Cunningham
I just spent several hours on this stupid problem
我只是在这个愚蠢的问题上花了几个小时
First, change permissions using this in terminal
首先,在终端中使用此更改权限
find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
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
我不知道 664 和 775 之间有什么区别我都这样做了 775 另外 htdocs 需要目录路径,例如对我来说是
/usr/local/apache2/htdocs
find htdocs -type f -exec chmod 775 {} + -o -type d -exec chmod 775 {} +
This is the other dumb thing too
这也是另一个愚蠢的事情
make sure that your image src link is your domain name for instance
例如,确保您的图片 src 链接是您的域名
src="http://www.fakedomain.com/images/photo.png"
Be sure to have
一定要有
EnableSendfile off in httpd.conf file
EnableMMAP off in httpd.conf file
You edit those using pico in terminal
您在终端中使用 pico 编辑那些
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
我还专门为图片创建了一个目录,这样当你在浏览器地址栏输入 domainname.com/images 时,你会得到一个可以下载的照片列表,需要成功下载以表明图像文件正常工作
<Directory /usr/local/apache2/htdocs/images>
AddType images/png .png
</Directory>
And those are the solutions I have tried, now I have functioning images... yay!!!
这些是我尝试过的解决方案,现在我有正常运行的图像......耶!!!
Onto the next problem(s)
下一个问题
回答by Roland
I was having the same problem with a virtual host on Ubuntu 14.04
我在 Ubuntu 14.04 上的虚拟主机上遇到了同样的问题
For me the following solution worked:
对我来说,以下解决方案有效:
http://ubuntuforums.org/showthread.php?t=2185282
http://ubuntuforums.org/showthread.php?t=2185282
It's just adding a <Directory >
tag to /etc/apache2/apache2.conf
它只是添加一个<Directory >
标签/etc/apache2/apache2.conf
回答by cagcak
If you did everything right, just give the permission home directory like:
如果您做的一切都正确,只需授予主目录的权限,例如:
sudo chmod o+x $HOME
then
然后
sudo systemctl restart apache2
回答by TornaxO7
I had this issue on Arch Linux too... it costs me some time but I'm happy now that I found my mistake:
我在 Arch Linux 上也遇到了这个问题……这花了我一些时间,但现在我很高兴我发现了我的错误:
My directory with the .html
files where in my account.
I set everything on r+x
but I still got the 403
error.
Than I went completely back and tried to set my home-directoryto executewhich solved my problem.
.html
我的帐户中包含文件的目录。
我设置了所有内容,r+x
但仍然出现403
错误。
然后我完全回去并尝试将我的主目录设置为执行这解决了我的问题。