Configure Nginx for PHP 8 Linux Azure App Service
Published Jan 24 2022 10:53 PM 49.9K Views

Azure App Service for Linux platform now supports customer using both PHP 7 and PHP 8 built-in docker image. 

When switching from PHP 7 to PHP 8, you may recognize the platform changed the web container from using Apache to Nginx. If you previously defined custom rules in .htaccess will be lost and will highly possible break your app.


But Nginx does not have an equivalent to the .htaccess file, you need to update the main configuration and reload Nginx for any changes to take effect. NGINX is designed to be efficient. While using .htaccess can do harm to performance. For more details, please refer to


This article shows how to deploy a customized Nginx configuration in PHP 8 Linux App Service.


Inside App Service built-in PHP 8 docker image, the Nginx configuration is stored in /etc/nginx/sites-enabled/default file.

The following steps can be used to create your own customized Nginx configuration based on the default one.


1. Firstly, we need to copy /etc/nginx/sites-enabled/default to the /home folder

By default, App Service set WEBSITES_ENABLE_APP_SERVICE_STORAGE = true.  Files stored in /home path are persisted in an Azure Storage file share, which can survive restart and shared across scale instances. So we need to save your own Nginx configure file under /home path.

Go to App Service WEBSSH via https://<AppServiceName>

cp /etc/nginx/sites-enabled/default /home/default


2. Make Nginx configuration changes to the /home/default file.

vi /home/default

For example, we can turn off absolute_redirect, change root path, add rewrite rules, etc.



3. Use custom startup script to overwrite original Nginx config file. So the platform can use your configuration to start the Nginx server every time the App Service being started.

Go to “Configuration” --> “General settings” in the App service Portal.
Add the following command in the “Startup Command

cp /home/default /etc/nginx/sites-enabled/default; service nginx restart


When you change the Startup Command and save the setting, the App Service will be Restarted and begin to use your customized configuration to start the Nginx server.


More Reference Documents:



Version history
Last update:
‎Jan 23 2022 04:13 AM
Updated by: