root: Set the requested root directory
path to After the Nginx server receives the request, it searches for the root directory path of the resource
As follows, there is an images directory under the main directory of nginx, and there is a picture in it
Next we change the default access path in the nginx.conf configuration file to the picture in the 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 homepage again and find that You can directly access our own configured files
alias: used to change the URI of location
path is the modified root path
location /images { alias D:/dev-tools/nginx/V1/nginx-1.16.1/images; }
Restart the service and access the following path again
Or configure it as follows
Using alias, you can make the nginx file directory into a FTP function
The processing result of root is: root path location path
The processing result of alias is :Use alias path to replace location path
alias is the definition of a directory alias, root is the meaning of the top-level directory
If the location path If it ends with /, then alias must also end with /. There is no requirement for root
The above is the detailed content of How to set resource request directory in nginx. For more information, please follow other related articles on the PHP Chinese website!