error-handling - 在Nginx中,它必须是自动索引或目录禁止错误?

标签 error-handling nginx

我在图像目录/images/upload上不断收到“目录禁止错误”。

通过在该目录上添加自动索引,我可以消除此错误。但是我不希望人们看到该目录下的内容。

如何清除此错误?

Nginx配置

server
{
  listen       80;
  server_name  www.no-dev.com;
  index        index.php index.html index.htm;
  root         /opt/www/no_web;

  location ~ .*\.(php|php5)?$
  {
    #fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include       fastcgi.conf;
  }

  #location /images {
  #  autoindex on;
  #}

  location ~* \.(css|js)$ {
              add_header  Last-Modified: $date_gmt;
              expires 1y;
              access_log off;
  }

  location ~* \.(jpg|jpeg|gif|png|ico|bmp|swf)$ {
              expires max;
              access_log off;
  }
  access_log logs/no-dev.log main;
}

最佳答案

您有以下设置:

index        index.php index.html index.htm;

这意味着关闭自动索引功能后,您的网络服务器将针对每个请求目录路径的请求:
  • 在该目录中查找index.php,如果找到
  • ,则将其返回
  • 如果未找到index.php,它将查找index.html并返回该
  • 如果也找不到index.html,它将返回一个index.htm
  • (如果找不到)将返回403

  • 因此,如果要避免出现403错误页面,则需要在该目录中设置index.php,index.html或index htm。

    另外,您可以设置error_page 403 some_page.html;以返回看起来不同的403结果。

    关于error-handling - 在Nginx中,它必须是自动索引或目录禁止错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15427480/

    相关文章:

    linux - NGINX cookie 免费域配置设置小问题

    ssl - Nginx SSL 配置不适用于移动浏览器

    shell - 忽略setenv命令中的错误,并继续执行csh脚本

    php - 当存在索引问题时,查询/准备语句中未使用索引

    NGINX 反向代理和 Access-Control-Allow-Origin 问题

    python - django nginx静态文件404

    sql - Zope : standard_error_message: ZSQLMethod not working

    c++ - Boost::Spirit - on_error 不打印

    R lme4 错误在 '/usr/lib/rstudio/bin/rsession' : malloc(): memory corruption:

    docker - 在使用 nginx 部署应用程序时访问 URL 路由时如何修复 404 not found?