Nginx or use of koa

In doing recently uploaded pictures need to think how to upload pictures after the visit, because the back end is Node, start trying to write a special interface to find images by the incoming path, tried it does not feel good, because you want to set for each type of file Content-Type, or change the browser will download the file directly.

koa-static scheme

Since the rear end of the frame is used koa, employed koa-staticto achieve the following:

import staticServer from 'koa-static';

app.use(staticServer(__dirname, '/upload'));

If uploadthere are directory logo.pngfile, you can through the URL http://cms.thinktxt.com/logo.pngaccess to.

Nginx program

Nginx naturally good at hosting static resources, and ultimately selected program is hosted by Nginx, so also can liberate Node service pressure, configuration is as follows:

server {
    listen          80;
    server_name     cms.thinktxt.com;

    location / {
        大专栏  利用Nginx或koalass="kn">proxy_pass  http://127.0.0.1:8080;
        client_max_body_size    1000m;
    }

    location /images {
        root e:/WorkSpace/Thinktxt-CMS/upload/;
    }
}

If the uploaddirectory imageshas a directory logo.pngfile, you can through the URL http://cms.thinktxt.com/images/logo.pngaccess to.

If you want other systems to access other resources at the site directory, you can do the forwarding:

server {
    listen          80;
    server_name     static.thinktxt.com;

    location /images {
        proxy_pass http://cms.thinktxt.com/images;
    }
}
Related tags
qrcode-pay

Guess you like

Origin www.cnblogs.com/lijianming180/p/12147526.html