If you want the path following the domain name to point to other directories on the local disk instead of the default web directory, you need to set up nginx directory access redirection. Application scenario: dashidan.com/image automatically jumps to dashidan.com/folderName/image. There are four ways to implement nginx directory path redirection. Modify the root mapping, redirect internally through Nginx rewrite, set up alias mapping, and implement it through nginx's permanent 301 absolute redirect. 1 nginx modifies root mapping Modifying the root mapping to redirect nginx directory access is the simplest way and is recommended. location /image { root /folderName; } 2 Access redirection through nginx rewrite internal jump Nginx configuration code example: location /image { rewrite ^/image/(.*)$ /folderName/image/$1 last; } 3 nginx alias mapping implementation Configuration example: location /image { alias /folderName/image; #Write the absolute path here} 4. Implemented through nginx's permanent 301 absolute redirect Configuration example: location /image { rewrite ^/image/(.*)$ http://dashidan.com/folderName/image/$1; } 5. Redirect page by judging URI Configuration example: if ( $request_uri ~* ^(/image)){ rewrite ^/image/(.*)$ /folderName/image/$1 last; } nginx location matching rules location matching command ~ #The wavy line indicates a regular match, case-sensitive
The priority of location matching (regardless of the order of locations in the configuration file) = Exact matches are processed first. If an exact match is found, nginx stops searching for further matches. Ordinary character matching, regular expression rules and long block rules will be given priority over query matching, which means that if the item matches, it is necessary to see if there is a regular expression match and a longer match. ^~ only matches this rule and nginx stops searching for other matches. Otherwise, nginx continues to process other location instructions. Finally, the instructions with "~" and "~*" are matched. If a corresponding match is found, nginx stops searching for other matches. When there is no regular expression or no regular expression is matched, the verbatim match instruction with the highest degree of match will be used. location = / { # Only matches "/". [ configuration A ] } location / { # Matches any request, because all requests start with "/" # But longer character matches or regular expression matches will take precedence [ configuration B ] } location ^~ /images/ { # Match any request starting with /images/ and stop matching other locations [ configuration C ] } location ~* \.(gif|jpg|jpeg)$ { # Matches requests ending with gif, jpg, or jpeg. # But all requests to the /images/ directory will be handled by [Configuration C]. [ configuration D ] } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: MySQL 5.7.10 winx64 installation and configuration method graphic tutorial (win10)
>>: WeChat applet selects the image control
The front-end development department is growing, ...
Table of contents 1. context 1. Usage scenarios 2...
The use of ElementUI paging component Pagination ...
Table of contents What are hooks? Class Component...
1. Introduction to inode To understand inode, we ...
(1) Each HTML tag has an attribute style, which c...
The warning points in this article have nothing t...
There are many servers that can host static websi...
I saw this question in the SQL training question ...
Ubuntu 18.04, other versions of Ubuntu question: ...
Table of contents introduce Support Intel CPU Sup...
HTML operation principle: 1. Local operation: ope...
Table of contents Prerequisites DNS domain name r...
1. The as keyword indicates an assertion In Types...
1: Check the PHP version after entering the termi...