Puzzled nginx rewrite rules
習慣沉默
習慣沉默 2017-05-27 17:45:03
0
2
798

The picture above is a simple example that I configured according to the nginx longest match principle. The purpose is to deny all access to /, but to be able to jump normally when accessing /hello. However, for cashback, access to /hello is still 403, but The rewrite log records that nginx did match my rules, why did it still return 403 to me? Please help me understand, thank you very much!

習慣沉默
習慣沉默

reply all (2)
刘奇

location / can match all requests

You can modify it as follows

location = / { deny all; }

Grammar rules: location [=|~|~*|^~] /uri/ { … }
= The beginning means an exact match
^~ The beginning means the uri starts with a regular string, which can be understood as matching the url path. nginx does not encode the URL, so the request is /static/20%/aa, which can be matched by the rule ^~ /static/ /aa (note the space). The beginning of
~ indicates case-sensitive regular matching
~* The beginning indicates case-insensitive regular matching
!~ and !~* are case-sensitive non-matching and case-insensitive non-matching regular matching respectively
/ universal matching, Any request will be matched

    曾经蜡笔没有小新

    Because /test00 after rewrite matches location /

    You should add a location ~ ^/test00 and enable access

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!