简体   繁体   English

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

[英]Fixing 403 Forbidden on alias directory with Apache

I am trying to setup an alias to point to some directory on my filesystem not in DocumentRoot. 我正在尝试设置别名以指向我的文件系统上的某个目录而不是DocumentRoot。 Now I get a 403 Forbidden response. 现在我收到403 Forbidden回复。 These are the steps taken: 1. edit http.conf, adding: 以下是采取的步骤: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

I was having this issue on OS X too. 我也在OS X上遇到过这个问题。 It turned out gliptak was right, but I've some more detail to add. 事实证明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 . 主文件夹是/Users/calrion
  • Virtual directory folder is /Users/calrion/Path/to/www . 虚拟目录文件夹是/Users/calrion/Path/to/www
  • There's a symlink /Users/calrion/Path pointing to /Volumes/Other/Users/calrion/Path . 有一个指向/Volumes/Other/Users/calrion/Path的符号链接/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/calrion and /Volumes/Other/Users/calrion . 问题是用户和组_www (Apache在OS X上运行)缺少对/Users/calrion/Volumes/Other/Users/calrion执行访问权限。

Running chmod o+x /Users/calrion and chmod o+x /Volumes/Other/Users/calrion resolved the issue (on OS X 10.7.4). 运行chmod o+x /Users/calrionchmod o+x /Volumes/Other/Users/calrion解决了问题(在OS X chmod o+x /Volumes/Other/Users/calrion上)。

The rule here is that Apache requires execute access to all folders in the path in order to serve files. 这里的规则是Apache需要对路径中的所有文件夹执行访问才能提供文件。 Without this, you'll get a HTTP 403 (forbidden). 没有这个,你将获得HTTP 403(禁止)。

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)需要访问您的家!

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. 我在OSX服务器中指定了一个指向用户目录的别名。 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. 我花了很长时间chmodding并弄乱了_www用户,递归地添加了可执行权限,卸载了macports以及各种尝试使其工作的东西。 I tried 777. Nope. 我试过777.不。 No idea why it wasn't working. 不知道为什么它不起作用。

Eventually, I just checked the "shared folder" checkbox in the Finder for that folder, and it worked, on the specified domain, with php active, the way I wanted it to. 最后, 我刚刚在Finder中检查了该文件夹中的“共享文件夹”复选框 ,并且它在指定的域上工作,使用php激活,就像我想要的那样。 :/ ...so that was easy. :/ ...这很容易。

Check permission on /Users/user/Documents/ , /Users/user/ (higher level permissions are enforced first ...) 检查/Users/user/Documents//Users/user/权限(首先强制执行更高级别的权限...)

/bin/su into the user running Apache (like www, www-data) and cat a file in the /Users/user/Documents/example directory. /bin/su进入运行Apache的用户(如www,www-data)和cat /Users/user/Documents/example目录下的文件。 That might point you to permission problems with your setup. 这可能会指向您的设置权限问题。

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已启用,并且我的别名目录中的文件的安全上下文不正确,缺少httpd_sys_content_t。

You can view the security context with ls -Z . 您可以使用ls -Z查看安全性上下文。 If your files/folders don't have httpd_sys_content_t then apache won't server them up! 如果您的文件/文件夹没有httpd_sys_content_t,那么apache将不会为它们提供服务! You can add the proper context with something like chcon -R --type=httpd_sys_content_t /new_html_directory . 您可以使用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). 这将更改当前目录中文件的上下文,但不会更改之后添加的任何文件(为此您需要使用semanage)。 Your other option is to just leave the files under /var/www. 您的另一个选择是将文件保留在/ var / www下。

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 . 此更改实现了apache更新中从2.2到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). 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:如果你打算升级到优胜美地,那么就要花一周的时间来解决它所破坏的一切

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 上面和其他帖子上的所有gentelmen在他们的答案中都有一些正确的部分,但下面是总和

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 希望这会有所帮助

I had to revert my apache config file and then set up the server again. 我不得不还原我的apache配置文件,然后再次设置服务器。 found this useful: https://apple.stackexchange.com/questions/41143/how-to-revert-default-mac-apache-install-to-original 发现这很有用: https//apple.stackexchange.com/questions/41143/how-to-revert-default-mac-apache-install-to-original

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 {} \;

It certainly does look right, do a sanity check. 它确实看起来正确,做一个健全检查。

  • you restarted apache 你重新启动了apache

  • check group and user ownership 检查组和用户所有权

  • I think the quotes can be removed 我认为报价可以删除

  • there is something in /Users/user/Documents/example ? / Users / user / Documents / example中有什么内容?

  • try 777 试试777

-sean -Sean

SELinux was the culprit for me. SELinux是我的罪魁祸首。 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. 如果你在Linux机箱上遇到这个问题而你的别名和文件权限是正确的,那么尝试执行“setenforce 0”将SELinux置于许可模式。 That did the trick for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM