Image files (.png) 404 not found error although they exist on server

PNG files which are definitely existing on the server in the correct directory (I double-checked) throw a 404 Not found (nginx) error. The strange thing is that .pdf files which are also stored under the /public/storage/.../documents path are shown correctly. So, perhaps this is an nginx conf issue? I already checked permission of files and nginx conf.

Permissions of files:
The directory where the .png files are in has drwxrws---+ permissions and the files themselves have -rw-rwx---+ permissions. Note that also the .pdf files in the same dir which are displayed correctly have the exact same permissions.

Nginx configuration:
I took a look into invoiceninja5.conf under /etc/nginx/conf.d/domain.tld.d where I found the following:

 location ~* \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
    try_files $uri /var/www/invoiceninja5/public/index.php$request_uri;
    # Optional: Don't log access to other assets
    access_log off;

I’m not too deep into nginx config. Does this look correct considering the .png files are located under /public/storage/…/documents ?

Can anybody help with this? I want to be able to access my uploaded images in InvoiceNinja.


@david do you have any suggestions?


We have a sample nginx config here:

try using this

Following your advice @david I commented out the extra blog I posted above and reloaded nginx. Afterwards I can access my images via the dedicated link but there is still an ImageCodecException when embedding the image in InvoiceNinja. The error message is the following:

ImageCodecException: Failed to detect image file format using the file header.
File header was [0x3c 0x21 0x44 0x4f 0x43 0x54 0x59 0x50 0x45 0x20].
Image source: encoded image bytes: https://domain.tld/api/v1/...


I also ran php artisan optimize after reloading nginx. Still, the embedded image is not displayed correctly. What can I do? Thank you.

@hillel thoughts on this error?

Are you able to share a sample image for us to try to reproduce the error?

It really happens with any .png image. So, I don’t think this is file related but here you go:

Maybe this will help:

Thank you @hillel. I just checked my /etc/hosts file and it has this line localhost

I don’t think this should produce any errors. Also please note that I am not running InvoiceNinja inside of a docker container. It’s installed natively on a Debian server and my error message is slightly different. It doesn’t say File header was empty as in your linked thread but File header was [...]. Any other suggestions?

Sorry, I’m not sure.