我在图像目录/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;
这意味着关闭自动索引功能后,您的网络服务器将针对每个请求目录路径的请求:
因此,如果要避免出现403错误页面,则需要在该目录中设置index.php,index.html或index htm。
另外,您可以设置
error_page 403 some_page.html;
以返回看起来不同的403结果。
关于error-handling - 在Nginx中,它必须是自动索引或目录禁止错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15427480/