apachectl localhost 加载图片资源失败,错误403

Apachectl localhost failing to load image resource, error 403

我正在启动一个用 Javascript 编写的小脚本,从 HTMLtext_script.html:

加载一个简单的图像
<body>
    <img src="firstcar.gif" name="slide" width="100" height="56" /> 
    <script>
        Var image = [];
        image[0]=new Image(); 
        image[0].src="firstcar.gif“; 
        image[1]=new Image() 
        Image[1].src="secondcar.gif“;
        var step=0;

        function slideit(){
          document.images.slide=image[step] ;
          if (step<image.length) step++ else step=0; 
          setTimeout("slideit()",2500) 
        } 
        slideit(); 
    </script>

</body>

这是我的 Documents 文件夹的结构,其中包含脚本和 3 个图像,firstcar.gitsecondcar.gifthirdcar.gif:

问题是当我在浏览器上执行代码时,它 returns 这个错误,`无法加载资源:服务器响应状态为 403(禁止):

现在,我已经通过停止并重新启动服务器进行了检查: sudo apachectl startsudo apachectl stop 并且我还仔细检查了文件的路径,但是这些方法中的 none 有效。

我怀疑是权限问题?如何解决?

您使用的是什么服务器? Windows 还是 Linux?将权限更改为 777。好吧,首先复制所有代码,以便您可以返回。假设 Linux:

cd /var/www/
sudo cp -rp htdocs backup
sudo chmod -R 777 htdocs

如果现在能用,那就是权限问题。您知道权利设置不正确。您可以复制原始文件夹并将权限更改为更安全的文件夹。

您可能需要为 Apache 设置读取权限,或更改 apache/httd 进程的所有者。该用户的名称取决于您的服务器(Centos 或 Debian)and/or 配置。

另一个问题可能是这样的:https://askubuntu.com/questions/413887/403-forbidden-after-changing-documentroot-directory-apache-2-4-6

如果您使用的是 Apache 2.2,在这种情况下您应该使用:

<Directory /home/everett/webroot>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

对于 Apache 2.4 使用此:

<Directory [write_your_dir_here]>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

所以这是关于 Require all grantedOrder allow,deny + allow from all