在以前的一篇博文中介紹了Nginx負載均衡的實現,本篇文章就簡單介紹下如何用Nginx搭建一個文件服務器。html
在以前的一篇博文中已經講述過了,這裏就不在講述了。
地址:Nginx Linux和Windows安裝教程 :http://www.javashuo.com/article/p-bnglcmqs-cx.htmlnginx
Nginx的配置這塊和普通的同樣就能夠了,只要在nginx/html 目錄新增文件便可。而後經過Nginx的IP加上文件的路徑便可下載,好比在nginx/html目錄建立一個test目錄,而後在test目錄在建立一個xuwujing.txt和xuwujing.zip的文件,最在瀏覽器輸入 http://localhost:8080/test/xuwujing.zip,便可進行下載。瀏覽器
示例圖:
服務器
上述的配置能夠簡單知足一些要求,可是有時候咱們想經過nginx進行下載其餘的格式的文件時候,好比下載一張圖片,可是訪問這個url瀏覽器會自動展示這張圖片,那麼這時咱們就能夠經過增長配置,而且讓瀏覽器下載該圖片。
例如,咱們在訪問test目錄的靜態文件,那麼咱們在nginx/conf中添加以下配置便可!app
location /test { add_header Content-Disposition "attachment;"; }
示例圖:負載均衡
未加配置的時候:
url
添加配置的時候:
.net
Nginx的文件路徑默認在安裝的nginx/html 目錄下,若是咱們想改變這路徑,能夠將location 的root 路徑進行更改,好比更改到opt目錄下 :code
location / { root /opt/nginx/nginx-1.8.0/html; index index.html index.htm; }
那麼nginx/conf的配置以下server
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8080; server_name localhost; location / { root /opt/nginx/nginx-1.8.0/html; index index.html index.htm; } location /test { add_header Content-Disposition "attachment;"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
Nginx Linux和Windows安裝教程:http://www.javashuo.com/article/p-bnglcmqs-cx.html
SpringBoot+SpringCloud實現負載均衡: http://www.javashuo.com/article/p-nyffgbcx-ek.html
Nginx+SpringBoot實現負載均衡: http://www.javashuo.com/article/p-pmokrpxe-gk.html
原創不易,若是感受不錯,但願點贊或推薦!您的支持是我寫做的最大動力!
版權聲明:
做者:虛無境
博客園出處:http://www.cnblogs.com/xuwujing
CSDN出處:http://blog.csdn.net/qazwsxpcm
掘金出處:https://juejin.im/user/5ae45d5bf265da0b8a6761e4
我的博客出處:http://www.panchengming.com