macos 使用 Apache 修复别名目录上的 403 Forbidden

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6807317/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:13:24  来源:igfitidea点击:

Fixing 403 Forbidden on alias directory with Apache

apachemacospermissionsoperating-systemalias

提问by sjking

I am trying to setup an alias to point to some directory on my filesystem not in DocumentRoot. Now I get a 403 Forbidden response. These are the steps taken: 1. edit http.conf, adding:

我正在尝试设置一个别名以指向我的文件系统上的某个目录而不是 DocumentRoot。现在我收到 403 Forbidden 响应。这些是采取的步骤: 1. 编辑 http.conf,添加:

Alias /example "/Users/user/Documents/example"

then...

然后...

<Directory "/Users/user/Documents/example">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride None
   Order allow,deny
   Allow from all</Directory>

2. setting permissions with chmod in terminal:

2.在终端用chmod设置权限:

chmod 755 /Users/user/Documents/example

Now it should work? instead I get the access forbidden. This is the output from error_log:

现在它应该工作了吗?相反,我禁止访问。这是 error_log 的输出:

[Sun Jul 24 06:57:57 2011] [error] [client xx.xx.xx.xx] (13)Permission denied: access to /example denied

采纳答案by Calrion

I was having this issue on OS X too. It turned out gliptakwas right, but I've some more detail to add.

我在 OS X 上也有这个问题。事实证明gliptak是对的,但我还有更多细节要补充。

We're both attempting to configure a virtual directory for a folder under a user's home folder; I think this is why we're having the problem. In my case, I had the following setup:

我们都试图为用户主文件夹下的文件夹配置虚拟目录;我认为这就是我们遇到问题的原因。就我而言,我有以下设置:

  • Home folder is /Users/calrion.
  • Virtual directory folder is /Users/calrion/Path/to/www.
  • There's a symlink /Users/calrion/Pathpointing to /Volumes/Other/Users/calrion/Path.
  • 主文件夹是/Users/calrion.
  • 虚拟目录文件夹是/Users/calrion/Path/to/www.
  • 有一个符号链接/Users/calrion/Path指向/Volumes/Other/Users/calrion/Path.

The problem was the user and group _www(which Apache runs as on OS X) lacked execute access to /Users/calrionand /Volumes/Other/Users/calrion.

问题是用户和组_www(Apache 在 OS X 上运行)缺乏对/Users/calrion和 的执行访问权限/Volumes/Other/Users/calrion

Running chmod o+x /Users/calrionand chmod o+x /Volumes/Other/Users/calrionresolved the issue (on OS X 10.7.4).

运行chmod o+x /Users/calrionchmod o+x /Volumes/Other/Users/calrion解决了问题(在 OS X 10.7.4 上)。

The rule here is that Apache requires execute access to allfolders in the pathin order to serve files. Without this, you'll get a HTTP 403 (forbidden).

这里的规则是Apache 需要对路径中的所有文件夹进行执行访问才能提供文件。没有这个,你会得到一个 HTTP 403(禁止)。

回答by Mirco Ellmann

The last straw ;) Required local in the Directory Entry...

最后一根稻草 ;) 在目录条目中需要本地...

like

喜欢

<Directory "/Users/user/Documents/example">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Require local
   Order allow,deny
   Allow from all
</Directory>

if everything else doesn't work (correct Alias, Directory Entry in httpd.conf and correct mod/usr/grp).

如果其他一切都不起作用(正确的别名、httpd.conf 中的目录条目和正确的 mod/usr/grp)。

keep in mind: if you put your site in user-space the apache user (running httpd) needs access to your home!

请记住:如果您将站点置于用户空间,则 apache 用户(运行 httpd)需要访问您的家!

回答by gliptak

Check permission on /Users/user/Documents/, /Users/user/(higher level permissions are enforced first ...)

检查权限/Users/user/Documents//Users/user/(首先强制执行更高级别的权限...)

/bin/suinto the user running Apache (like www, www-data) and cata file in the /Users/user/Documents/exampledirectory. That might point you to permission problems with your setup.

/bin/su进入运行 Apache 的用户(如 www、www-data)和cat目录中的一个文件/Users/user/Documents/example。这可能会指出您的设置存在权限问题。

回答by greenland

These are all very good answers. None of them worked for me.

这些都是很好的答案。他们都没有对我来说有效。

I have an alias specified in OSX server pointing to a user directory. I spent a long while chmodding and messing with _www user, adding executable permissions recursively, uninstalling macports and all sorts of stuff trying to get this to work. I tried 777. Nope. No idea why it wasn't working.

我在 OSX 服务器中指定了一个指向用户目录的别名。我花了很长时间 chmodding 并弄乱 _www 用户,递归添加可执行权限,卸载 macports 和各种试图让它工作的东西。我试过 777。不行。不知道为什么它不起作用。

Eventually, I just checked the "shared folder" checkboxin the Finder for that folder, and it worked, on the specified domain, with php active, the way I wanted it to. :/ ...so that was easy.

最终,我只是在 Finder 中选中了该文件夹的“共享文件夹”复选框,并且它在指定的域上工作,并且 php 处于活动状态,就像我想要的那样。:/ ...所以这很容易。

回答by sudol

I was just having this exact same issue. What I found was SE_Linux was enabled, and the security context of the files in my Aliased directory was incorrect, missing httpd_sys_content_t.

我只是遇到了完全相同的问题。我发现启用了 SE_Linux,并且我的 Aliased 目录中文件的安全上下文不正确,缺少 httpd_sys_content_t。

You can view the security context with ls -Z. If your files/folders don't have httpd_sys_content_t then apache won't server them up! You can add the proper context with something like chcon -R --type=httpd_sys_content_t /new_html_directory. This will change the context of the files currently in the directory, but not any files that are added afterwards (for that you'll need to work with semanage). Your other option is to just leave the files under /var/www.

您可以使用 来查看安全上下文ls -Z。如果您的文件/文件夹没有 httpd_sys_content_t,那么 apache 将不会为它们提供服务!您可以使用类似的内容添加适当的上下文chcon -R --type=httpd_sys_content_t /new_html_directory。这将更改当前目录中文件的上下文,但不会更改之后添加的任何文件(为此您需要使用 semanage)。您的另一个选择是将文件保留在 /var/www 下。

回答by edan

Here's what fixed it for me:

这是为我解决的问题:

in /etc/apache2/httpd.conf

/etc/apache2/httpd.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None

    # REMOVE THESE LINES
    #Order deny,allow
    #Deny from all

    # ADD THIS LINE
    Require all denied
</Directory>

This change implements changes made in the apache update from 2.2 to 2.4. The OSX Yosemite update brought the apache update with it (PSA: if you're planning on upgrading to Yosemite, budget yourself a week to fix everything it breaks).

此更改实现了从 2.2 到 2.4apache 更新中所做的更改。OSX Yosemite 更新带来了 apache 更新(PSA:如果您计划升级到 Yosemite,请为自己安排一周的时间来修复它破坏的所有内容)。

The weird thing is that I already got apache 2.4 working, and suddenly it breaks again....

奇怪的是,我已经让 apache 2.4 正常工作了,突然它又坏了....

PSA: if you're planning on upgrading to Yosemite, budget yourself a week to fix everything it breaks

PSA:如果您打算升级到优胜美地,请为自己安排一周的时间来修复所有损坏的地方

回答by Razmig

After lots of time waste i fixed the issue and i wanted to share to save your time.

经过大量时间浪费后,我解决了这个问题,我想分享以节省您的时间。

All the gentelmen above and on other posts has some correct parts in their answers but below is the sum

上面和其他帖子上的所有绅士在他们的答案中都有一些正确的部分,但下面是总和

In your "/etc/apache2/httpd.conf" file:

在您的“/etc/apache2/httpd.conf”文件中:

1- change your document root

1- 更改您的文档根目录

Original: DocumentRoot "/Library/WebServer/Documents"
Change to: DocumentRoot "/Users/yourname/www"

2- change

2-改变

Original:

原来的:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

Change to:

改成:

<Directory /Users/yourname/www>
    Options FollowSymLinks Includes ExecCGI
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

3- Change:

3- 改变:

Original:

原来的:

<Directory "/Library/WebServer/Documents">

Change to:

改成:

<Directory "/Users/yourname/www">

4- Finally, you might not need this step if you are the supper user, this is to set the right permition on your new root folder

4- 最后,如果你是超级用户,你可能不需要这一步,这是在你的新根文件夹上设置正确的权限

chmod 755 /Users/yourname/www

Hope this will help

希望这会有所帮助

回答by TacoEater

I had to revert my apache config file and then set up the server again. found this useful: https://apple.stackexchange.com/questions/41143/how-to-revert-default-mac-apache-install-to-original

我不得不恢复我的 apache 配置文件,然后再次设置服务器。发现这很有用:https: //apple.stackexchange.com/questions/41143/how-to-revert-default-mac-apache-install-to-original

回答by Israelmikan

Quick Solution:

快速解决方案:

Use these commands as root on Linux:

在 Linux 上以 root 用户身份使用这些命令:

find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;

回答by ktbiz

SELinux was the culprit for me. If you're having this issue on a linux box and your alias and file permissions are correct than try doing a "setenforce 0" to put SELinux into permissive mode. That did the trick for me.

SELinux 是我的罪魁祸首。如果您在 linux 机器上遇到此问题并且您的别名和文件权限正确,请尝试执行“setenforce 0”以将 SELinux 置于许可模式。那对我有用。