拓冰建站拓冰建站
首页 / 资讯中心 / 正文

Nginx简单快速搭建文件服务器

一、前言nginx的配置这块和普通的一样就可以了只要在nginx/html 目录新增文件即可。然后通过Nginx的IP加上文件的路径即可下载比如在nginx/html目录创建一个test目录然后在test目录在创建一个001.txt文件最在浏览器输入 http://localhost:10007/01/001.txt 即可进行下载。二、静态文件下载上述的配置可以简单满足一些要求但是有时候我们想通过nginx进行下载其他的格式的文件时候比如下载一张图片但是访问这个url浏览器会自动展现这张图片那么这时我们就可以通过增加配置并且让浏览器下载该图片。例如我们在访问test目录的静态文件那么我们在nginx/conf中添加如下配置即可!location/{add_header Content-Dispositionattachment;;}未加配置的时候:添加配置的时候:三、指定文件存放路径Nginx的文件路径默认在安装的nginx/html 目录下如果我们想改变这路径可以将location 的root 路径进行更改比如更改到/opt/soft/wno704/images目录下 :location/{root/opt/soft/wno704/images;index index.html index.htm;}如果配置多个目录路径指定用“alias”具体如下location/file{alias/opt/file;index index.html index.htm;}location/image{alias/opt/image;index index.html index.htm;}四、nginx.conf 配置http{include mime.types;default_type application/octet-stream;sendfile on;#tcp_nopush on;server_tokens off;#keepalive_timeout0;keepalive_timeout65;client_body_timeout100;client_header_timeout100;send_timeout100;limit_conn_zone $binary_remote_addr zoneconn_zone:100m;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 logs/access.log main;server{listen10007;server_name localhost;location/{root/opt/soft/wno704/images;index index.html index.htm;add_header Content-Dispositionattachment;;}location/file{alias/opt/file;index index.html index.htm;add_header Content-Dispositionattachment;;}location/image{alias/opt/image;index index.html index.htm;add_header Content-Dispositionattachment;;}error_page500502503504/50x.html;location/50x.html{root html;}}}
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门