Home  >  Q&A  >  body text

Regarding nginx location matching issues

When configuring nginx to support php-fpm, I found a problem, configure it as shown below

It is no problem to access http://host/server.php at this time

But when I removed it

As shown in the picture

There is a problem accessing http://host/server.php at this time

Please tell me why there must be a ~ number

My original understanding was that the uri /server.php can match location php and the matching length is longer than location / (3:1), so in this case it is the same whether there is ~ or not, but the result is unexpected

Please tell me, God, what is going on?

迷茫迷茫2714 days ago449

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:11:23

    • Start with = to indicate an exact match

    • For example, A only matches requests at the end of the root directory, and cannot be followed by any string.

    • The beginning of
    • ^~ means that the uri starts with a regular string, not a regular match

    • The beginning of
    • ~ indicates case-sensitive regular matching;

    • ~* starts with case-insensitive regular matching

    • / Universal matching, if there is no other match, any request will be matched

    I’ve never seen anything like yours that doesn’t fit the bill.
    Refer to nginx configuration location summary and rewrite rule writing

    reply
    0
  • Cancelreply