Files synced with Azure storage account (AzureFiles NOT AzureBlob) into the Linux app service running a custom container gives a 502 bad gateway error.

Hamood Rehman 1 Reputation point
2021-10-11T18:14:56.787+00:00

Context

I am using Azure File Share to sync my media files in the app service every time a container starts. The reason I am using File Share and not Blob storage is because there is no write access (only read access) provided by Azure for Blob storage feature, more info on that here. Moreover the file sync works fine with the File Share storage i.e. I can see the files that were uploaded into the Azure File Share inside my container mount path which is: /var/www/html/<app-name>/web/sites/default/files and the Drupal 9.2.4 application that the container is running can also write to the same mount path and I can see the newly created files on the File Share as well.

Issue

The issue is all the images/PDFs files inside the above mount path show a 502 Bad Gateway on the browser, however the CSS files that the Drupal application loads inside the same mount path work fine. The web application works fine, the issue is ONLY with the images being loaded in the above mount path.

Link to the web application: rtastaged9.azurewebsites.net

The site is not using a SSL.

Things that I have already tried and do not work:

  1. Changed the tier of File Share from 'Hot' to 'Performance Optimized'.
  2. Scaled up the app service plan to use P2V3 (16 GB memory) from P1V3 (8 GB memory).
  3. Set the FQDN (Servername) of the apache2 in the container to be: rtastaged9.azurewebsites.net
  4. The Log stream in the app service shows 200 OK for the same images/PDFs that are showing 502 Bad Gateway on the browser.
  5. The default_docker.log under /LogFiles/ of app service also shows images/PDFs 200 OK.
  6. The Drupal's /admin/reports/dblog shows no sign of any 502 Bad Gateway errors.
  7. Tried clearing cache with drush cr command.

Moreover if the container is not connected to the storage account, the images/PDFs in the above mount path work fine but of-course the files would not persist that way in the container.

Also just in case below is my Dockerfile that I am using to build the Drupal container and pushing it to Azure Container Registry and from there I am using the app service to use the image plus an Azure MySQL instance is connected to the same app service. Let me know if you want me to provide any more info, would appreciate any help.

FROM osiolabs/drupaldevwithdocker-php:7.4

ENV APACHE_DOCROOT_DIR=/var/www/html/<app-name>/web/
#Set the Server name
ENV APACHE_SITE_NAME=rtastaged9.azurewebsites.net
#Set the Server alias
ENV APACHE_SITE_ALIAS=rtastaged9.azurewebsites.net

COPY /<app-name> /var/www/html/<app-name>

RUN composer self-update --2

WORKDIR /var/www/html/RTA-D8 
RUN composer install
WORKDIR ../../../../

# ssh for azure app service
ENV SSH_PASSWD "root:Docker!"
RUN apt-get update \
        && apt-get install -y --no-install-recommends dialog \
        && apt-get update \
&& apt-get install -y --no-install-recommends openssh-server \
&& echo "$SSH_PASSWD" | chpasswd 
RUN mkdir /run/sshd
COPY sshd_config /etc/ssh/

EXPOSE 80 443 2222 

CMD /usr/sbin/sshd && apachectl -D FOREGROUND
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,537 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,960 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Davie Lau 6 Reputation points
    2021-10-13T23:33:41.14+00:00

    I had the exact same issue as you. The following link helped: https://azureossd.github.io/2020/09/15/unable-to-download-static-content-php-on-azure-app-service-linux/index.html

    I added the following to my apache2.conf file:

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

    Replace ${APACHE_DOCUMENT_ROOT} with your document root which appears to be /var/www/html/<app-name>.

    1 person found this answer helpful.

  2. SnehaAgrawal-MSFT 22,706 Reputation points Moderator
    2021-10-12T10:17:29.557+00:00

    Thanks for asking question! If you are experiencing problem with site, you may check the docker log, this is helpful in troubleshooting your site when it doesn't start or if it's restarting. Different ways to access Docker logs is below:

    1. Docker logs appear on the Container Settings page in the portal.
    2. You can find the Docker log in the /LogFiles directory. You can access this via the Kudu (Advanced Tools) Bash console or by using
      an FTP client to access it.
    3. You can use our API to download the current logs.

    Could you try to configure, add an app setting called WEBSITES_CONTAINER_START_TIME_LIMIT and set it to the number of seconds to 1800 As, by default, if your container does not respond after 230 seconds, it will time out.

    Check this blog link: https://learn.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux#if-your-container-takes-a-long-time-to-start-increase-the-start-time-limit

    Also, set the WEBSITES_PORT app setting in your App Service app. That is an WEBSITES_PORT as one of your app settings with the port your app is listening As by default, App Service assumes your custom container is listening on port 80.

    Please note that App Service currently allows your container to expose only one port for HTTP requests.

    Please review the following article that might help you customize and configure your Web App to your requirements

    https://learn.microsoft.com/en-us/azure/app-service/containers/configure-custom-container

    Let us know if issue further query or issue remains.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.