Forum: NGINX Nginx static file serving - Some files are 404, some not

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Lantos István (Guest)
on 2016-07-06 14:39
(Received via mailing list)
I have the following server configuration block:

> {      root /var/www/html/public;      access_log off;      expires max;
> }    error_page 401 403 404      /404.html;    error_page 500 502 503 504
> /50x.html;}*

I want to server my static files with Nginx to my Node/Express app. I
want to re-factore every single route in my app, that's why i want to
server all these static files into / URL path.

The problem is some files cannot be located on the disk, although they
existing, for example  */images/art/lindon.png*.

This is a docker-compose stack and nginx built from source:

The error message that I got for a missing file:

*lantosistvan_nginx | 2016/07/06 14:24:42 [error] 6#6: *3 open()
> "/var/www/html/public/images/art/lindon.png" failed (2: No such file or
> directory), client:, server: localhost, request: "GET
> /images/art/lindon.png HTTP/1.1", host: "", referrer:
> "
> <>"*

Is there any better way to server static files for the / URL without
blocking* location / {}*?

Thank You for your help!

Lantos István (Guest)
on 2016-07-06 15:45
(Received via mailing list)
Sorry, the parent folder, /images/art was uncommented in .gitignore,
why didn't uploaded into my repo. Problem solved.

Still, is there any method to share static files? Something like expose
public folder into / URL, but without blocking the route?

2016-07-06 14:38 GMT+02:00 Lantos István <>:
B.R. (Guest)
on 2016-07-06 18:51
(Received via mailing list)
location / only means 'a location which starts with /'. Basically, this
catches every single request, and is the least specific way (lowest
precedence ever) to do so.
When choosing the most suitable location block, nginx will most of the
use a more specific one. That is why this is called 'default location'.

One way I understand your question:
If you want to have a specific behavior for the '/' path, you could
use location
= / which matches only this *exact* path and has the highest precedence,
a match with the requested path makes this block immediately selected.

Another way:
If you want to first browse your filesystem and fall back (in case no
matches) to proxying the request to backends, that is not what your
configuraiton file tells nginx to do.
You would need something like:
location / {
    try_files $uri $uri/ @fallback;
    autoindex on;

location @fallback {
    <proxy work>
*B. R.*
Richard Stanway (Guest)
on 2016-07-06 19:02
(Received via mailing list)
This topic is locked and can not be replied to.