using the following rules.
If nginx is on the local machine, the static directory is also on the local machine,
1. The subdirectories match the
following configuration
location / { root /data/www; }
When visiting http://127.0.0.1/, match /data/www
when visiting http://127.0.0.1/images, match /data/www/images and
visit http://127.0.0.1/images/1. jpg, match /data/www/images/1.jpg
That is, the path after "/" in the address bar directly matches the path under
the For configuration
location /images/ { root /data/www; }
When visiting http://127.0.0.1/images, it matches /data/www/images
. That is to say, /images in the address bar directly matches the subdirectory of /data/www. What
often goes wrong is that the location in the location The url is arbitrarily assigned a name, such as /xxx, but the corresponding /data/www
directory does not have the /data/www/xxx subdirectory, and a 404 will be generated as soon as it is accessed.
2. Repeated path matching rules
For the following configuration:
server { location / { root /data/www; } location /images/ { root /data; } }
Accessing the URL http://localhost/images/example.png will match the second /images/ rule.
Although it can also match the location / rule, nginx will choose the longest prefix to match the current URL by default, that is, the
second This configuration will take effect, visit the /data/images/ directory instead of the /data/www/images/ directory
Article from: http://powertech.iteye.com/blog/2180942