As the company recently in the Nginx related projects, research the location of the rules, the main reference to the blog post for Http://www.jb51.net/article/47761.htm, but the actual operation of their own, found some problems.
The priority of location is this
Assume that the access path is 127.0.0.1/a/1.jpg
The priority is location =/a/1.jpg > Location/a/1.jpg > Location ^~/a/> Location ~*\.jpg$ > location/a/> Locati On/
And then I'm going to start with the steps.
#1 location/{return 500;} #2location/a/{return 404;} #3location ~* \.jpg$ {return 403;} #4location ^~/a/{return 402;} #5location/a/1.jpg {return 401;} #6location =/a/1.jpg {return 400;}
1. Put all the contents of the first write off, do not write off the words must be reported repeated errors, Nginx reload
Access the 127.0.0.1/a/1.jpg to get a return value of 400
2. Then write down all content within the range, Nginx reload, re-access 127.0.0.1/a/1.jpg, the return value is
403! Not 401 in the article
3. Go ahead, write down all content in # #, Nginx Reload, revisit 127.0.0.1/a/1.jpg, and get a return value of 401
4. Then write off within the # #,nginx Reload, re-access the 127.0.0.1/a/1.jpg, the resulting return value is 402
5. Then write down the content within the # #, but need to restore the content of # #,nginx Reload, re-access the 127.0.0.1/a/1.jpg, the return value is 404
In this case the order actually becomes
Location =/a/1.jpg > Location ~*\.jpg$ > location/a/1.jpg > Location ^~/a/> location/a/> Loc ation/
Now that you can only pick them out alone,
1. When there are # # and # #
#3location ~* \.jpg$ {return 403;} #4location ^~/a/{return 402;}
Access 127.0.0.1/a/1.jpg The return value is actually 402, according to the above results should be 403 AH
2. When there are # # and # #
#4location ^~/a/{return 402;} #5location/a/1.jpg {return 401;}
The return value obtained by accessing 127.0.0.1/a/1.jpg is 401, which is in accordance with the above order
3. At the time of # # and # #
#3location ~* \.jpg$ {return 403;} #5location/a/1.jpg {return 401;}
The return value obtained by accessing 127.0.0.1/a/1.jpg is 403
4. At the same time that there are # # and # # and # #
#3location ~* \.jpg$ {return 403;} #4location ^~/a/{return 402;} #5location/a/1.jpg {return 401;}
Visit 127.0.0.1 and get 403.
If you see this article, if you have the luck, you know, please tell me in the comments, I appreciate
About Nginx Location rules