Page Views: 25 views
How do I redirect a directory path in nginx? In order to solve this problem, this article introduces the corresponding analysis and answer in detail. I hope it can help more partners who want to solve this problem to find a more simple and easy way.

It is the easiest way to modify root mapping to realize nginx directory access redirection, which is recommended.
Location / image {
Root / folderName
}
Example of nginx configuration code:
Location / image {
Rewrite ^ / image/ (. *) $/ folderName/image/$1 last
}
Example configuration:
Location / image {
Alias / folderName/image; # write the absolute path here
}
Example configuration:
Location / image {
Rewrite ^ / image/ (. *) $http://dashidan.com/folderName/image/$1;
}
Example configuration:
If ($request_uri ~ * ^ (/ image)) {
Rewrite ^ / image/ (. *) $/ folderName/image/$1 last
}
and the following four points:
Exact matching will be the first to be processed. If an exact match is found, nginx stops searching for other matches.
Normal character matching, regular expression rules and long block rules will be matched first with the query That is, if the match also needs to see if there is a regular expression match and a longer match.
^ ~ only this rule is matched, and nginx stops searching for other matches, otherwise nginx will continue to process other location instructions.
Finally, match the instructions with "~" and "~ *". If the corresponding match is found, nginx stops searching for other matches. When there is no regular expression or no regular expression is matched, then the most matching verbatim matching instruction will be used.
Location = / {
# Only match "/".
[configuration A]
}
Location / {
# Match any request, because all requests start with "/"
# But longer character matching or regular expression matching takes precedence
[configuration B]
}
Location ^~ / images/ {
# Match any request that starts with / images/ and stop matching other location
[configuration C]
}
Location ~*\. (gif|jpg|jpeg) ${
# Match requests that end with gif, jpg, or jpeg.
# But all requests for the / images/ directory will be processed by [Configuration C].
[configuration D]
}
This is the answer to the question about how to redirect the directory path in nginx. I hope the above content can be of some help to you, if you still have a lot of doubts to be solved. You can follow the billionaire Cloud Industry Information Channel to learn more about it.