nginx作为web服务器,实现文件下载
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#前端静态页面
location / {
root /home/workshop/projections/frontend;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /excel/ {
#需要下载的文件存放的目录
alias /home/excel/;
sendfile on;
autoindex on; # 开启目录文件列表
autoindex_exact_size on; # 显示出文件的确切大小,单位是bytes
autoindex_localtime on; # 显示的文件时间为文件的服务器时间
#autoindex_format html; # 以网页的风格展示目录内容。该属性在1.7.9及以上适用
charset utf-8,gbk; # 避免中文乱码
}
#后台文件
location /apis {
rewrite ^.+apis/?(.*)$ /$1 break;
proxy_pass http://localhost:8811;
proxy_connect_timeout 18000s;
proxy_send_timeout 18000s;
proxy_read_timeout 18000s;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
autoindex_exact_size off;
默认为on,显示出文件的确切大小,单位是bytes。
改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
autoindex_localtime on;
默认为off,显示的文件时间为GMT时间。
改为on后,显示的文件时间为文件的服务器时间