nginx location
URL,
Syntax
location [modifier] pattern { ... }Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
() |
location /api/ { ... } |
Common | |
= |
location = / { ... } |
Common | |
~ |
() | location ~ \.php$ { ... } |
Advanced |
~* |
() | location ~* \.(jpg|png|gif)$ { ... } |
Advanced |
^~ |
() | location ^~ /static/ { ... } |
Advanced |
Examples
location ~* \.(css|js|jpg|png|gif|ico)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}and 30
API
location /api/ {
proxy_pass http://localhost:3000/;
}/api/users → localhost:3000/users
Home
location = / { # / /about
}location ~ /\. {
deny all;
return 404;
}.git,.env and more
Common Errors
location: = > ^~ > ~ >. nginx -T
Tips
- : (=) > (^~) > (~) >
- proxy_pass /
- try_files SPA