How does nginx set the resource request directory?


Method 1: use rootroot: set the requested root directory

Path is the root directory path for searching resources after Nginx server receives the request.

The case demonstration is as follows: there is a directory of images in nginx's home directory, which contains a picture.

Let's change the default access path in the nginx.conf configuration file to the picture in this directory above, as follows:

location / {  #root html;   #index  index.html  index.htm ; root D:/dev-tools/nginx/V1/nginx-1.16.1/images; index 2.jpg; }

After restarting the nginx service, visit the home page again and find that we can directly access the files configured by ourselves.

Method 2: Use aliasalias: the URI

Path is the modified root path.

Case display location/images {alias d:/dev-tools/nginx/v1/nginx-1.16.1/images; }

Restart the service and visit the following path again.

Or configured as follows.

Using alias, you can make nginx's file directory with FTP function.

The difference between root and alias The result of root processing is: root path +location path.

The processing result of alias is: replace the location path with alias path.

Alias is the definition of a directory alias, and root is the meaning of the top-level directory.

If the location path ends with/,alias must also end with/,which is not required by root.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us