In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How do I redirect a directory path in nginx? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
1 nginx modify root mapping
It is the easiest way to modify root mapping to realize nginx directory access redirection, which is recommended.
Location / image {root / folderName;}
2 access redirection through nginx rewrite internal redirection
Example of nginx configuration code:
Location / image {rewrite ^ / image/ (. *) $/ folderName/image/$1 last;}
3. Implementation of alias alias mapping for nginx settings
Example configuration:
Location / image {alias / folderName/image; # write the absolute path here}
4 it is realized by permanent 301absolute jump of nginx
Example configuration:
Location / image {rewrite ^ / image/ (. *) $http://dashidan.com/folderName/image/$1;}
5 realize page jump by judging uri
Example configuration:
If ($request_uri ~ * ^ (/ image)) {rewrite ^ / image/ (. *) $/ folderName/image/$1 last;}
Nginx location matching rule
Location matching command
~ # wavy line means that a regular match is performed, which is case-sensitive
~ * # means to perform a regular match, which is case-insensitive
^ ~ # ^ ~ indicates that ordinary characters match. If this option matches, only this option is matched, not other options. It is generally used to match directories.
= # for exact matching of ordinary characters
@ # "@" defines a named location, which is used when directed internally, such as error_page, try_files
The instruction of the = prefix strictly matches this query. If you find it, stop searching.
All the remaining regular strings, the longest match. If the match uses the ^ ~ prefix, the search stops.
Regular expressions, the order defined in the configuration file.
If rule 3 produces a match, the result is used. Otherwise, as from Rule 2 is used.
Priority of location match (regardless of the order of location in the configuration file)
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 preferentially matched 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 verbatim matching instruction with the highest degree of matching will be used.
Location = / {# only matches "/". [configuration A]} location / {# matches any request because all requests start with "/" # but longer character matching or regular expression matching takes precedence to match [configuration B]} location ^ ~ / images/ {# matches any request that starts with / images/ And stop matching other location [configuration C]} location ~ *\. (gif | jpg | jpeg) ${# match requests ending 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 industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.