skip to Main Content

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 (!).

2

Answers


  1. 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/

    Login or Signup to reply.
  2. I had the same root issue so thanks for sharing your solution. Azure support pointed me here to resolve my issue. I’ll share additional information for future reference and hopefully to help others.

    In my case I just added this line to the Apache config file because all my DocumentRoot is in /home:

    EnableMMAP Off
    

    I didn’t test it, but enabling EnableSendfile probably also doesn’t work based on the Apache docs.

    Important performance note

    I got very low performance with this configuration:

    • Linux Docker container
    • Website (PHP) stored and served from the persistent /home dir

    The same website stored in the Docker image instead of in /home gave a 6x request time speedup on the B1 plan. A B3 plan showed a 1.5x speedup. I didn’t test other web app plans.

    Investigation

    My starting point with this problem was that I wanted to use a single Docker image to host multiple PHP websites instead of storing the websites inside separate Docker images. The Web App persistent storage seemed like a great fit for this.

    The symptoms I noticed when my website was hosted in /home were:

    • HTML and JS files worked fine
    • image files returned status 400

    I increased the log level of Apache with LogLevel trace8 and noticed that files that served through mod_deflate worked fine while those that were served directly didn’t. Disabling mod_deflate made the HTML and JS files also fail with status 400. Using mod_deflate means that files aren’t served directly from disk and that the

    Unfortunately I didn’t connect the dots myself and I spent a lot of time trying various combinations of Docker images and Apache configurations…

    EnableMMAP is a performance optimization however so it might be worthwhile to actually store the different web apps in separate Docker images instead of using a single generic one with an external mount point.

    I’m also considering using Nginx instead of Apache to see if that changes anything:
    https://learn.microsoft.com/en-us/answers/questions/835092/app-service-stack-image.html
    https://techcommunity.microsoft.com/t5/apps-on-azure-blog/use-php-fpm-log-to-troubleshoot-php-8-linux-azure-app-service/ba-p/3275136

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search