preface
In a previous post on Nginx load balancing, this article will briefly introduce how to build a file server using Nginx.
Nginx installation
I covered it in a previous blog post, but I won’t cover it here. Address: Nginx Linux and Windows installation tutorial: www.cnblogs.com/xuwujing/p/…
Nginx configuration
The Nginx configuration section is just as normal, just add files to the Nginx/HTML directory. Nginx/HTML/xuwuJing.txt/xuwuJing.zip/xuwuJing.zip/xuwuJing.txt/xuwuJing.zip/xuwuJing.zip/xuwuJing.txt/xuwuJing.zip In the browser to http://localhost:8080/test/xuwujing.zip, you can download.
Figure:
Static file download
The above configuration can simply meet some requirements, but sometimes we want to use Nginx to download a file in another format, such as an image, but the url browser will automatically display the image, then we can add the configuration, and let the browser download the image. For example, if we are accessing static files in the test directory, we can add the following configuration to nginx/conf.
location /test {
add_header Content-Disposition "attachment;";
}
Copy the code
Figure:
When not configured:
When adding a configuration:
Specify the file storage path
The default Nginx file path is in the Nginx/HTML directory of the installation. If you want to change this path, you can change the root path of the location, for example, to the opt directory:
Location / {root /opt/nginx/nginx-1.8.0/ HTML; index index.html index.htm; }Copy the code
Nginx/conf configuration
So the nginx/conf configuration is as follows
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; }}}Copy the code
other
Related articles
Nginx Linux and Windows installation tutorial: www.cnblogs.com/xuwujing/p/… SpringBoot + SpringCloud load balancing: www.cnblogs.com/xuwujing/p/… Nginx + SpringBoot load balancing: www.cnblogs.com/xuwujing/p/…
Music to recommend
Original is not easy, if you feel good, hope to praise or recommend! Your support is the biggest motivation for my writing! Copyright: www.cnblogs.com/xuwujing CSDN blog.csdn.net/qazwsxpcm Nuggets: juejin.cn/user/365003… Personal blog: www.panchengming.com