dockerazure-web-app-servicelaravel-8azure-files

Laravel in Docker on Azure webapp can't serve images from mounted file storage


I have an azure web app with a custom container running apache, php 7.4 with laravel and a mounted azure file storage.
Serving .png files from a mounted storage does work for my local build in docker desktop and it works on a testystem on a physical machine.

Storage is mounted to /var/www/data_persistent and laravel serves data from /var/www/api/public. To preserve the data that is displayed images are written to the storage to be served.

I have a link from inside the public folder to one in the storage ln -fs /var/www/data_persistent/maps /var/www/api/public/maps

On Azure, if I request an image in any folder of maps I get a 400 response, if the file is completely empty it works.

this is how it looks on the webapp:

total 28
4 drwxr-xr-x 2 root root 4096 Aug 11 13:17 css
0 -rwxr-xr-x 1 root root    0 Jan 28  2022 favicon.ico
4 drwxr-xr-x 3 root root 4096 Aug 11 13:17 images
4 -rwxr-xr-x 1 root root 1785 Feb  4  2022 index.php
4 drwxr-xr-x 2 root root 4096 Aug 11 13:17 js
0 lrwxrwxrwx 1 root root   29 Aug 11 13:20 maps -> /var/www/data_persistent/maps 

and this is inside maps:

total 29943
    0 drwxrwxrwx 2 nobody nogroup        0 Jul 10 23:41 .
    0 drwxrwxrwx 2 nobody nogroup        0 May 29 16:23 ..
    0 drwxrwxrwx 2 nobody nogroup        0 Jul 28 15:36 1
 2715 -rwxrwxrwx 1 nobody nogroup  2779239 Jul 28 15:47 1.tif
    0 drwxrwxrwx 2 nobody nogroup        0 Jul 28 12:34 7
27229 -rwxrwxrwx 1 nobody nogroup 27881853 Jul 28 12:43 7.tif 

Writing to the file storage works, the folders and files you see are the result of uploads from frontend and a script. Any help is appreciated.

UPDATE 17.08.2022: I have tried quite some options, like
EnableSendfile off
in the apache conf in sites-enabled but no luck until now. Interestingly the Apache log show status code 200 when serving the images.

ALSO serving html files does work from the mounted storage, but only if they are valid html content (!).


Solution

  • The problem seems to be the setting EnableMMAP in apache.

    Add EnableMMAP Off to <Directory "${APACHE_DOCUMENT_ROOT}"> in apache2.conf

    Example for this block of /etc/apache2/apache2.conf

    <Directory "${APACHE_DOCUMENT_ROOT}">
        Options Indexes FollowSymLinks
        EnableMMAP Off
        AllowOverride None
        Require all granted
    </Directory>
    

    Source: https://azureossd.github.io/2020/09/15/unable-to-download-static-content-php-on-azure-app-service-linux/