Home  >  Article  >  Operation and Maintenance  >  How to set resource request directory in nginx

How to set resource request directory in nginx

王林
王林forward
2023-05-22 22:37:041586browse

    Method 1: Use root

    root: Set the requested root directory

    How to set resource request directory in nginx

    path to After the Nginx server receives the request, it searches for the root directory path of the resource

    Case demonstration

    As follows, there is an images directory under the main directory of nginx, and there is a picture in it

    How to set resource request directory in nginx

    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

    How to set resource request directory in nginx

    Method 2: Use alias

    alias: used to change the URI of location

    How to set resource request directory in nginx

    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 access the following path again

    How to set resource request directory in nginx

    Or configure it as follows

    How to set resource request directory in nginx

    How to set resource request directory in nginx

    Using alias, you can make the nginx file directory into a FTP function

    The difference between root and alias

    • 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!

    Statement:
    This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete