Linux 如何配置下载目录中任何文件的NGINX服务器
我正在尝试在Linux上配置NGINX服务器,它可以从目录下载任何文件 但我面临的问题是,如果文件是文本文件,或者文件名包含空格和(“()”#“&”)等特殊字符,那么浏览器将不会提供任何信息,也不会提供任何信息 我如何解决这个问题? 我的配置为fallowsLinux 如何配置下载目录中任何文件的NGINX服务器,linux,nginx,centos,nginx-location,winginx,Linux,Nginx,Centos,Nginx Location,Winginx,我正在尝试在Linux上配置NGINX服务器,它可以从目录下载任何文件 但我面临的问题是,如果文件是文本文件,或者文件名包含空格和(“()”#“&”)等特殊字符,那么浏览器将不会提供任何信息,也不会提供任何信息 我如何解决这个问题? 我的配置为fallows http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
#default_type application/*;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {}
错误\u第404/404.html页;
错误\u第500页502 503 504/50x.html 要下载文件而不是在浏览器中显示文件,MIME类型应设置为
application/octet stream
。它通常被声明为默认类型
通常,nginx
使用文件扩展名来确定要使用哪种MIME类型,但是可以通过使用空集指定types
指令在某个位置关闭该功能
可以使用URL中的%编码字符访问带有奇怪字符的文件名
作为实验,您可能需要打开autoindex
并关闭index
来浏览文件。这还将向您显示,您的疑难文件名也可以下载
location / {
index not_a_file;
autoindex on;
types {}
}
注意:我不知道有什么机制可以关闭索引
,只是将其设置为一个不太可能的名称。默认的index.html
可能不会与下载目录的内容冲突
更多信息请参见。什么不是文件?@dieter请参见我答案末尾的斜体注释。