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

How to set resource request directory in nginx

王林
Release: 2023-05-22 22:37:04
forward
1653 people have browsed it

    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;
    }
    Copy after login

    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;
     }
    Copy after login

    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!

    Related labels:
    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template