apache 403 禁止在 web root 中的符号链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2218086/
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
403 Forbidden on symlink in web root
提问by Pekka
I am on a shared hosting package on a LAMP stack with no shell access.
我在 LAMP 堆栈上的共享托管包上,没有外壳访问权限。
I can create symlinks using PHP's symlink()function.
我可以使用 PHP 的symlink()函数创建符号链接。
Let's say my web root is /home/www/user1/public
假设我的网络根是 /home/www/user1/public
Let's say I have a real directory named /home/www/user1/public/real_dir
假设我有一个名为的真实目录 /home/www/user1/public/real_dir
And I create a symlink named /home/www/user1/public/fake_dirpointing to real_dir
我创建了一个名为/home/www/user1/public/fake_dir指向的符号链接real_dir
Why would I get a 403 Forbiddenwhen trying to access www.mydomain.com/fake_dirbut not when trying to access www.mydomain.com/real_dir?
为什么我在尝试访问时会收到403 Forbidden 而在尝试访问www.mydomain.com/fake_dir时却没有www.mydomain.com/real_dir?
It shouldn't be a rights problem because when I create a file in PHP, I can access that all right.
这不应该是权限问题,因为当我在 PHP 中创建文件时,我可以访问它。
I tried switching FollowSymlinksoff and on in .htaccess (it was on), but no luck.
我尝试FollowSymlinks在 .htaccess 中关闭和打开(它是打开的),但没有运气。
Could it be that FollowSymlinksis defined as not overwritable in a .htaccess file? Or is there something else to be aware of when working with Symlinks in Apache?
是否FollowSymlinks在 .htaccess 文件中定义为不可覆盖?或者在 Apache 中使用符号链接时还有什么需要注意的吗?
采纳答案by Sam
Apache has to be configured to allow access to the directory on the filesystem. This has to be done by a system administrator by inserting a <Directory> directive in the apache configuration files (httpd.conf).
Apache 必须配置为允许访问文件系统上的目录。这必须由系统管理员通过在 apache 配置文件 (httpd.conf) 中插入 <Directory> 指令来完成。
Since the real directory is inside the web root it must be accessible, but FollowSymLinks may not have been enabled for the directory - this also has to be added to the <Directory> directive.
由于真实目录位于 Web 根目录内,因此它必须是可访问的,但可能尚未为该目录启用 FollowSymLinks - 这也必须添加到 <Directory> 指令中。
See http://httpd.apache.org/docs/2.0/mod/core.html#directory
回答by Kenny Kang
This is possible SELinux security issue.
这可能是 SELinux 安全问题。
cat /selinux/enforce if the value is 1, set it to 0, then restart apache.
cat /selinux/enforce 如果值为1,则将其设置为0,然后重新启动apache。

