nginx 下载文件全都不区分大小写
时间: 2023-07-25 19:46:04 浏览: 44
要使nginx下载文件路径不区分大小写,可以在nginx配置文件中添加以下语句:
```
server {
listen 80;
server_name example.com;
location / {
# 不区分大小写
if ($request_uri ~* ^/download) {
rewrite ^(.*)$ /DOWNLOAD/$1 permanent;
}
# 下载文件
location /DOWNLOAD/ {
root /path/to/files; # 下载文件的根目录
autoindex on; # 允许列出目录内容
autoindex_exact_size off; # 允许列出目录内容时显示文件大小的单位
add_header Content-Disposition attachment; # 设置下载文件的HTTP头信息
}
}
}
```
其中,`if`语句和`rewrite`语句的作用与上一个回答中的相同。`location /DOWNLOAD/`表示下载文件的URL路径,`root`指定了下载文件的根目录,`autoindex on`表示允许列出目录内容,`autoindex_exact_size off`表示允许列出目录内容时显示文件大小的单位,`add_header Content-Disposition attachment`表示设置下载文件的HTTP头信息,使浏览器能够正确地下载该文件。这样一来,无论用户请求的下载文件URL路径是`/download`还是`/DOWNLOAD`,都会下载该文件。