Nginx static file serving - Some files are 404, some not
Richard Stanway
r1ch+nginx at teamliquid.net
Wed Jul 6 17:02:25 UTC 2016
Check out try_files.
http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
On Wed, Jul 6, 2016 at 3:44 PM, Lantos István <kerozin.joe at gmail.com> wrote:
> Sorry, the parent folder, /images/art was uncommented in .gitignore,
> that's why didn't uploaded into my repo. Problem solved.
>
> Still, is there any method to share static files? Something like expose
> the public folder into / URL, but without blocking the route?
>
> 2016-07-06 14:38 GMT+02:00 Lantos István <kerozin.joe at gmail.com>:
>
>> I have the following server configuration block:
>>
>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *server { # Running port listen 80; # ipv4 listen
>>> [::]:80; # ipv6 server_name localhost; root
>>> /var/www/html; # Proxying the connections connections location /
>>> { proxy_pass http://app <http://app>;
>>> proxy_redirect off; proxy_set_header Host $host;
>>> proxy_set_header X-Real-IP $remote_addr; proxy_set_header
>>> X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header
>>> X-Forwarded-Host $server_name; } location ~
>>> ^/(fonts/|gallery/|images/|javascripts/|stylesheets/|ajax_info\.txt|apple-touch-icon\.png|browserconfig\.xml|crossdomain\.xml|favicon\.ico|robots\.txt|tile-wide\.png|tile\.png)
>>> { 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 not
>> 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:
>>
>> https://github.com/DJviolin/lantosistvan/blob/be8e49e2302793d37ed3bfdec865f7086e579197/docker/nginx/Dockerfile
>>
>> 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: 10.0.2.2, server: localhost, request: "GET
>>> /images/art/lindon.png HTTP/1.1", host: "127.0.0.1", referrer:
>>> "http://127.0.0.1/hu/blog/mariya-balazs
>>> <http://127.0.0.1/hu/blog/mariya-balazs>"*
>>>
>>
>> Is there any better way to server static files for the / URL without
>> blocking* location / {}*?
>>
>> Thank You for your help!
>>
>> István
>>
>>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20160706/350f223c/attachment.html>
More information about the nginx
mailing list