简体   繁体   English

别名 403 禁止使用 Apache

[英]Alias 403 Forbidden with Apache

I'm trying to create a folder named week7 and an html page named hello.html in that folder outside the document root and have it viewed through an Alias directive.我正在尝试在文档根目录外的该文件夹中创建一个名为 week7 的文件夹和一个名为 hello.html 的 html 页面,并通过 Alias 指令查看它。

I created a folder named week7 out of the Document Root.我在文档根目录中创建了一个名为 week7 的文件夹。 I chose this location for it:我为此选择了这个位置:

/usr/local/www/week7

while my document root is:而我的文档根目录是:

/usr/local/www/apache22/data

in httpd.conf and under tag, I wrote:在 httpd.conf 和标签下,我写道:

    Alias /week7 /usr/local/www/week7
<Directory /usr/local/www/week7>
    Require all granted
</Directory>

After rebooting the server, I got the following message: Forbidden 403 message.重新启动服务器后,我收到以下消息:Forbidden 403 message。

I tried changing permissions for the hello.html file, the week7 folder and even the www folder and nothing changed.我尝试更改 hello.html 文件、week7 文件夹甚至 www 文件夹的权限,但没有任何改变。

Any ideas?有任何想法吗?

If you're using apache 2.4如果您使用的是 apache 2.4

Order allow,deny订单允许、拒绝
Allow from all允许所有

becomes...变成...

Require all granted要求全部授予

https://httpd.apache.org/docs/2.4/upgrading.html https://httpd.apache.org/docs/2.4/upgrading.html

I know it's old but just for the record, the following worked for me in XAMPP (Windows 8)我知道它很旧但只是为了记录,以下在 XAMPP (Windows 8) 中对我有用

Alias /projects c:/projects

<Directory c:/projects>
    Options Indexes FollowSymLinks MultiViews
    Order allow,deny
    Allow from all
</Directory>

EDIT编辑

On XAMPP 5.6 and Apache 2.4 try this:在 XAMPP 5.6 和 Apache 2.4 上试试这个:

Alias /projects c:/projects

<Directory c:/projects >
    Options Indexes FollowSymLinks MultiViews
    Require all granted
</Directory>

I fixed this issue with these directives:我用这些指令解决了这个问题:

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local

You'll only be able to browse from your local computer, but it works for local testing and development.您只能从本地计算机浏览,但它适用于本地测试和开发。

Trying the solutions offered by the other answers here, and finding they didn't work for me, using Linux Mint , I found another option to start apache as a different user.在这里尝试其他答案提供的解决方案,发现它们对我不起作用,使用Linux Mint ,我找到了另一种以不同用户身份启动 apache 的选项。

After reading unixd_module documentation , I edited "httpd.conf" to change the User and Group to that of the owner of the Alias directory (or root user) and the 403 "Forbidden" error had gone.阅读unixd_module 文档后,我编辑了“httpd.conf”以将UserGroup更改为Alias目录所有者(或 root 用户)的用户和组,并且 403“Forbidden”错误消失了。

  1. Open your "httpd.conf" at /opt/lampp/etc/httpd.conf (in a default installation of XAMPP for example) in a text editor.在文本编辑器中打开位于/opt/lampp/etc/httpd.conf的“httpd.conf”(例如在 XAMPP 的默认安装中)。

  2. Find <IfModule unixd_module> , where the comments should read something like:找到<IfModule unixd_module> ,其中的注释应该是这样的:

    If you wish httpd to run as a different user or group, you must run httpd as root initially and it will switch.如果您希望 httpd 以不同的用户或组运行,您必须首先以 root 身份运行 httpd,然后它会切换。

    User/Group: The name (or #number) of the user/group to run httpd as.用户/组:运行 httpd 的用户/组的名称(或#number)。

    It is usually good practice to create a dedicated user and group for running httpd, as with most system services.与大多数系统服务一样,创建专门的用户和组来运行 httpd 通常是一种很好的做法。

    with the default User and Group set to daemon .默认UserGroup设置为daemon

  3. Edit the User and Group .编辑UserGroup

For example:例如:

<IfModule unixd_module>
  User mrJohn
  Group mrJohn
</IfModule>

I hope this is useful.我希望这是有用的。

For me worked this solution:对我来说,这个解决方案是:

When I access the virtual directory an error “Access forbidden.当我访问虚拟目录时出现错误“禁止访问。 Error 403” occured.发生错误 403”。
The config seems to ok:配置似乎没问题:

Alias /static/ /home/username/sites/myblog/static/
<Directory /home/username/sites/myblog/static> Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride All Order allow,deny Allow from all </Directory>
Solution : The default apache configration is very restrictive.解决方案:默认的 apache 配置非常严格。 It do not allow to access directories without authentication.它不允许未经身份验证访问目录。 This is defined in the Directory section of httpd.conf: <Directory> AllowOverride none Require all denied </Directory>这是在 httpd.conf 的目录部分中定义的: <Directory> AllowOverride none Require all denied </Directory>
Add a “require all granted” directive to your virtual directory section will grant the access.将“要求全部授予”指令添加到您的虚拟目录部分将授予访问权限。

Alias /static/ /home/username/sites/myblog/static/ <Directory /home/username/sites/myblog/static> AllowOverride All Order allow,deny Allow from all Require all granted </Directory>

Alias /data /media/pi/VOLUME别名 /data /media/pi/VOLUME

..... .....

Options Indexes FollowSymLinks MultiViews期权索引 FollowSymLinks MultiViews

AllowOverride All允许覆盖所有

Require local需要本地

works fine on Raspbian for localhost在本地主机的 Raspbian 上运行良好

I was able to gain access to a directory outside the document root, but using the method proposed in the original question to this thread.我能够访问文档根目录之外的目录,但是使用了原始问题中建议的方法到这个线程。

   # Create Alias to access files for pure js front end app
   Alias "/hbt" "/dirA/dirB/dirC"

   # Create a Directory directive for "dirC"
   <Directory /dirA/dirB/dirC>
     Require all granted
   </Directory

Restarted Apache, and it worked.重新启动 Apache,它工作了。 I'm using Apache 2.4我正在使用 Apache 2.4

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

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