Updated April 5 2023
I’ve been doing a lot of Drupal work on Azure of late. I’ve noticed that a lot of documentation related to that awkward combination is out of date. Specifically, lots of docs talk about older versions of PHP App Services which use Apache. As of late November, those versions have been deprecated and all the current versions use Nginx**.
The Nginx config as supplied takes some changes to work with Drupal, particularly Drupal’s clean URL system (or WordPress’s equivalent URL slugs). Changing the config itself requires a couple tricks.
Get Nginx Using Your New Config
App services are basically Docker instances. Anything outside the /home/ directly gets nuked between restarts/instantiations/duplications/etc. So, you store your new config in the home directory. You can put it anywhere in there you like, but I use:
/home/nginx-configs/
copy the default nginx config there (this path is current as of January 2023, but it’s subject to change). We’re going to make our copy, default, and put a backup of the original into default.original:
cp /etc/nginx/sites-available/default /home/nginx-configs/default
cp /etc/nginx/sites-available/default /home/nginx-configs/defaul
t.original
Now we’re going to use an old trick: we’ll put our new config in that file, then set up the machine to copy it to overwrite the working config, then restart the service.:
cp /home/nginx_configs/default /etc/nginx/sites-enabled/default; service nginx restart
You might notice that we’re copying from sites-availbable but putting the file back in a different directory. That isn’t accidental. Sites-enabled is usually just a symbolic link to the config in sites-available, but in this case we’re putting the live file there. This allows us to use our new config without disturbing the original one in sites-available. If the default app service gets updated, you’ll be able to look at the original file for any config changes you might need to roll into your new config.
Anyway if it’s working, go to the Azure control panel and copy that command into the App Service configuration startup command. As of this writing, it lives under [app service control panel] > Configuration > General Settings
Make Your New Config New
So that gets the App Service using the config file you specified, but there’s nothing unique about that file yet. Let’s change that.
Inside the location { } block, place this directive:
# this enables Drupal clean URLS and WordPress URL slugs.
try_files $uri $uri/ /index.php?$args;
The default upload size is laughably small. Here is how to make it large. This goes in the server{} block, but outside the location{} block.
#allow uploads up to 100 megabytes
client_max_body_size 100M;
Now use the copy/restart command above to see if the new config is functioning.
And there you go. You should now have an App Service capable of running Drupal.
**officially pronounced ‘engine-x’, but that sounds like some band whose highest moment was opening for Limp Bizkit when the Warped Tour stopped in Akron. I encourage you to pronounce it phonetically. Say “Spilling inks”, then run that together into one word. Now drop the “spilli” part. nginks.