无法使用 Apache 服务器访问子目录中的文件

发布于 2024-12-20 14:06:46 字数 466 浏览 2 评论 0原文

我的 Windows 7 计算机上安装了 Apache 2.2.21 服务器。 我的网站已启动,/scripts 子目录中的脚本正在运行,但当我尝试从 /icons 加载图标时,出现 403 禁止错误。 我已经将其添加到我的 httpd.conf 文件中:

<Directory "c:/wamp/www/icons/">
    Options Indexes FollowSymLinks
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>

仍然没有效果。所以问题是:如何访问 /icons 子文件夹中的文件?

PS:使用 /images 子目录效果很好,但问题仍然存在。

I have an Apache 2.2.21 server installed on my Windows 7 machine.
My site is up and my scripts from /scripts subdirectory are working but when I try to load icons from /icons I get a 403 forbidden error.
I've already added this to my httpd.conf file:

<Directory "c:/wamp/www/icons/">
    Options Indexes FollowSymLinks
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>

Still no effect. So the question is: how can I access files in my /icons subfolder?

P.S.: Using /images subdirectory worked out just fine but the question still remains.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暗地喜欢 2024-12-27 14:06:47

在 Linux 操作系统中,如果您使用 Apache,则必须更改默认的 Apache 配置并编辑位于此处的此文件

/etc/apache2/mods-available/alias.conf

在此文件中,您必须在此行之前添加 # 进行注释

Alias /icons/ "/usr/share/apache2/icons/"

更改配置后,我必须重新启动 apache

sudo service apache2 restart

现在如果你检查它,它应该可以正常工作。

In Linux OS and if you use Apache, you have to change the default Apache configuration and edit this file located here

/etc/apache2/mods-available/alias.conf

In this file, you have to comment by putting # before this line

Alias /icons/ "/usr/share/apache2/icons/"

After changing the configuration, I had to restart apache

sudo service apache2 restart

And now if you check it, It should work properly.

您的好友蓝忘机已上羡 2024-12-27 14:06:47

好吧,如果你的 httpd.conf 没有做任何事情,你应该重新启动 apache。对文档所做的任何更改都必须重新启动,以便 Apache 可以“刷新”。

<Directory "c:/wamp/www/icons/">
     Options Indexes FollowSymLinks
     Order Deny,Allow
     Deny from all
     Allow from 127.0.0.1
</Directory>
  • 所以上面这是你的代码。它基本上在第 4 行中表示 Apache 应拒绝所有传入连接到 /icons/folder 的连接。

  • 第 5 行还表示仅允许来自 127.0.0.1 或 localhost 的传入连接。所以基本上服务器可以访问它!

  • 如果更改不起作用,您应该查看 .htaccess。另一种选择是从有效的文件夹中复制代码并粘贴它,然后从 EX 更改粘贴:
    将“C:/WAMP/www/images/”更改为“C:/WAMP/www/icons”。

Ok so if your httpd.conf doesn't do anyhting you should restart apache. Any changes done to documents have to be restarted so Apache can "Refresh".

<Directory "c:/wamp/www/icons/">
     Options Indexes FollowSymLinks
     Order Deny,Allow
     Deny from all
     Allow from 127.0.0.1
</Directory>
  • So above this is your code. It basically says in line 4 that Apache should deny connection from all incoming connections connections to the /icons/folder.

  • Also on line 5 it says to allow incoming connections from only 127.0.0.1 or localhost. So basically the server has access to it!

  • If changing it doesn't work you should look in .htaccess. Another option is just to copy the Code from a folder that works and paste it and just change the paste from EX:
    "C:/WAMP/www/images/" to "C:/WAMP/www/icons".

薯片软お妹 2024-12-27 14:06:46

您是否检查了 /icons 目录的 Windows 权限,并确保 Apache 用户可以读取该目录?图片中是否可能存在.htaccess文件?

编辑:好的,所以这不是权限。我的下一个猜测是:上面的配置显示“禁止所有人访问,除非他们来自 127.0.0.1”。但您使用的是 Windows 7。Windows 7 试图变得有用且现代 - 并且通常首先尝试通过 IPv6 进行访问。因此,您可能会显示为来自 ::1,这可能无法匹配 127.0.0.1。尝试关闭 IPv6 或添加 Allow from ::1 指令。

Have you checked the Windows permissions on the /icons directory, and made sure that the Apache user can read that directory? Is there possibly an .htaccess file in the picture?

Edit: Okay, so it's not permissions. My next guess is this: your config above says "everyone is forbidden access except when they're coming from 127.0.0.1". But you're on Windows 7. Windows 7 tries to be helpful and modern - and often tries accessing via IPv6 first. So you might show up as coming from ::1, which is probably failing to match 127.0.0.1. Try turning off IPv6 or adding an Allow from ::1 directive.

柒七 2024-12-27 14:06:46

我发现 /icons/ 被包含作为其他目录的别名。对我来说,配置文件位于:

C:\wamp\bin\apache\apache2.2.21\conf\extra\httpd-autoindex.conf

我必须注释掉这一行:

Alias /icons/ "c:/Apache22/icons/"

I figured out that /icons/ was included as an alias for some other directory. For me, configuration file was located at:

C:\wamp\bin\apache\apache2.2.21\conf\extra\httpd-autoindex.conf

I had to comment out this line:

Alias /icons/ "c:/Apache22/icons/"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文