using trailing slashes in nginx configuration
These locations are different. First one will match /production
for example, that might be not what you expected. So I prefer to use locations with a trailing slash.
Also, note that:
If a location is defined by a prefix string that ends with the slash character, and requests are processed by one of proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, or memcached_pass, then in response to a request with URI equal to this string, but without the trailing slash, a permanent redirect with the code 301 will be returned to the requested URI with the slash appended.
If you have something like:
location /product/ {
proxy_pass http://backend;
}
and go to http://example.com/product
, nginx will automatically redirect you to http://example.com/product/
.
Even if you don't use one of these directives above, you could always do the redirect manually:
location = /product {
rewrite ^ /product/ permanent;
}
or, if you don't want redirect you could use:
location = /product {
proxy_pass http://backend;
}
No, these are not the same--you will need to use a trailing slash with a regex to match both, i.e.
location ~ /product/?
See this related answer for a more detailed response on how to match the entire URL.