Nginx implements a simple image server (windows) + static file server

Requirement: Be able to use  http://localhost/directory/image name to access images that already exist locally (server)

First, you need to run nginx locally, using the default port 80 here;

Using http://localhost in the browser to see the following interface proves that nginx starts normally.


Next, you need to modify nginx.conf to realize the function of directly using http://localhost/upload/1.jpg to access the pictures of the server (here the local server is the server).

At present, I know that nginx supports two kinds: 1. Configure root, 2. Configure alias

The pictures of the local test are placed under the html folder of the nginx directory


The first:

root: The path of the splicing configuration behind the network access url

The configuration example is as follows:

location /images/ {
    root html;
    index  index.html index.htm;
 }

For this configuration, directly visit http://localhost/images/1.jpg to access the images in the images folder.

(The access path will be pointed to http://localhost/html/images/1.jpg)

The second:

alias: Directly points to the physical address of the object file.

The configuration example is as follows:

location /upload/ {
    alias E:/ljdworkspace/nginx-1.12.2/nginx-1.12.2/html/images/;
    autoindex is;
 }

For this configuration, directly visit http://localhost/upload/1.jpg to access the pictures in the images folder in the specified directory of the E disk.

After the above configuration is completed, the static file server is ok and you can directly visit http://localhost/upload/ to see the following picture


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324822756&siteId=291194637
Recommended