YunoHost-Apps / invoiceninja5_ynh

InvoiceNinja5 package for YunoHost
https://www.invoiceninja.org/
GNU General Public License v3.0
11 stars 6 forks source link

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

Closed CodeShakingSheep closed 6 months ago

CodeShakingSheep commented 1 year ago

Describe the bug

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;
  }

Please also check these posts: https://forum.yunohost.org/t/invoiceninja-5-image-files-png-404-not-found-error-although-they-exist-on-server/24767 https://forum.invoiceninja.com/t/image-files-png-404-not-found-error-although-they-exist-on-server/13366/4

Following the suggestion from the invoiceninja forum post I removed the nginx blog I posted above and reloaded nginx. With the block removed I can access my images via link but still they are not embedded correctly in the invoiceninja dashboard view. So, I think nginx configuration should be adjusted to render and embed images correctly.

Context

Steps to reproduce

  1. Create a recurring expense.
  2. Upload .png file to documents.

Expected behavior

The image should be accessible via image link and also be embedded correctly in InvoiceNinja 5 dashboard view.

Logs

This is the error message: 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/...

rndmh3ro commented 7 months ago

I can reproduce the problem. No idea how to fix this, yet.

CodeShakingSheep commented 7 months ago

@rndmh3ro Thanks for reproducing the issue on your side. In my case the problem was that my InvoiceNinja was only accessible to YNH users, not publicly accessible. The issue with this was that the YNH auth credentials weren't passed to the image requests which led to the 404 results. When I made my InvoiceNinja publicly available the images were loaded correctly. I shared the solution here: https://forum.invoiceninja.com/t/image-files-png-404-not-found-error-although-they-exist-on-server/13366/11

I think this is a problem with InvoiceNinja as it happens for any basic auth (not only the one from YNH). So, I think it needs to be fixed on their end. Can you confirm your InvoiceNinja isn't publicly accessible either?

rndmh3ro commented 7 months ago

Well actually my instance is available without logging in into YNH.. Still I get the 404. Strange.

CodeShakingSheep commented 6 months ago

I had the issue again that the PNG files were not rendered correctly inline. Instead, there was a 404 response again. I could fix it by commenting this whole block in etc/nginx/conf.d/domain.tld.d/invoiceninja5.conf.

 #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;
  #}

Afterwards my inline image is rendered correctly. image

Also, in the nginx sample from the documentation this block is not present: https://invoiceninja.github.io/en/self-host/#web-server-configuration

So, I suggest to remove this block from nginx config. What do you think @rndmh3ro ?