Location Matching in Nginx

From the Nginx cheat sheet ยท Location Blocks & Rewrites ยท verified Jul 2026

Location Matching

Different types of location matching

nginx
# Exact match
location = /exact {
    # Only matches /exact
}

# Prefix match
location /prefix {
    # Matches /prefix, /prefix/path, etc.
}

# Regex match
location ~ \.php$ {
    # Case-sensitive regex
}

# Regex case-insensitive
location ~* \.(jpg|jpeg|png)$ {
    # Case-insensitive regex
}
๐ŸŽฏ Exact match (=) has highest priority
๐Ÿ“ Regex locations are evaluated in order
๐Ÿ” Use ^~ to prevent regex matching
โšก Order matters for regex locations

Continue with Nginx

Save the full cheat sheet or work through every related task.

More Nginx tasks

Back to the full Nginx cheat sheet