nginx as download file server

WBOY
Release: 2016-07-30 13:29:49
Original
1027 people have browsed it

1. Foreword

When we want to share our files, there are many ways. LAN can use sharing, rtx transmission, qq transmission, send to mailbox, direct USB disk copy, etc. But the easiest thing is to start the local server, and other computers can download directly through the web page. Here is an introduction to using nginx as the server to download

2. Steps

1. Download nginx http://nginx.org/en/download.html The current stable version is 1.80. Unzip it to a directory

2. Modify the configuration file

nginx.conf
<code><span>#user  nobody;</span>
worker_processes  <span>1</span>;

<span>#error_log  logs/<span>error</span>.log;</span><span>#error_log  logs/<span>error</span>.log  notice;</span><span>#error_log  logs/<span>error</span>.log  info;</span><span>#pid        logs/nginx.pid;</span>events {
    worker_connections  <span>1024</span>;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    <span>#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '</span><span>#                  '$status $body_bytes_sent "$http_referer" '</span><span>#                  '"$http_user_agent" "$http_x_forwarded_for"';</span><span>#access_log  logs/access.log  main;</span>    sendfile        on;
    <span>#tcp_nopush     on;</span><span>#keepalive_timeout  0;</span>
    keepalive_timeout  <span>65</span>;

    <span>#gzip  on;</span>    server {
        listen       <span>8080</span>;
        server_name  localhost;

        <span>#charset koi8-r;</span><span>#access_log  logs/host.access.log  main;</span>        location / {
            <span>#root   html;</span><span>#index  index.html index.htm;</span><span>if</span> ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
            add_header Content-Disposition: <span>'attachment;'</span>;
            }
        }
        <span>#error_page  404              /404.html;</span><span># redirect server <span>error</span> pages to the static page /50x.html</span><span>#</span>
        error_page   <span>500</span><span>502</span><span>503</span><span>504</span>  /<span>50</span>x.html;
        location = /<span>50</span>x.html {
            root   html;
        }
    }
}</code>
Copy after login

3. Create the directory test and test.rar files in the html in the nginx directory

4. Open the command line and switch to nginx directory

4.1 Test script nginx -t
4.2 Start the server start nginx
4.3 Open the browser http://localhost:8080/test/test.rar The save as dialog box should pop up
4.4 Close the server nginx -s quit

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces nginx as a download file server, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!