window下使用nginx提供文件下载服务器配置
1.前言
当我们希望分享自己的文件时,有多种方式,局域网可以采用共享,rtx传输,qq传输,发送到邮箱,直接u盘拷贝等等。但最简单的就是开启本地服务器,其他电脑通过网页的方式直接下载,这里介绍使用nginx作为服务器进行下载
2.步骤
1.下载nginxhttp://nginx.org/en/download.html目前稳定版本为1.80解压到一个目录
2.修改配置文件
nginx.conf
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pidlogs/nginx.pid;
events{
worker_connections1024;
}
http{
includemime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
server{
listen8080;
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
#roothtml;
#indexindex.htmlindex.htm;
if($request_filename~*^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
add_headerContent-Disposition:'attachment;';
}
}
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}
}
}
3.在nginx目录下的html中建立目录test和test.rar文件
4.打开命令行切换到nginx目录
4.1测试脚本nginx-t
4.2开启服务器startnginx
4.3打开浏览器http://localhost:8080/test/test.rar应该弹出另存为对话框
4.4关闭服务器nginx-squit