How to boost your Azure web-server performance An open-source bootstrap script to configure Nginx, PHP, .NET, and WordPress caches on Azure’s local temp disk for faster, more efficient web apps

How to Migrate SQL Server DB to Azure SQL Server DB
Fork me on GitHub

If you’ve ever hosted web applications on Microsoft Azure, you probably know that every VM comes with a so-called ephemeral disk (usually mounted at /mnt). It’s fast, SSD/NVMe-backed storage with insane IOPS and low latency... but with a catch: its contents are temporary. As soon as the VM is deallocated or migrated to another host, everything on that disk is gone.

That might sound scary, but in practice it’s perfect for all those workloads that are, by nature, temporary: caches, session files, temp directories, build artifacts, and so on. If you configure your web stack to use that disk, you get a performance boost at no extra cost. That’s exactly the idea behind azure-tempdisk-bootstrap.

If you’re interested in getting the most out of Azure’s temporary disk, don’t miss this other post:  How to set Linux swapfile on an Azure VM temp disk. It’s the perfect companion to this article and shows how to set up a reliable swapfile on /mnt.

What does this project do?

I wrote azure-tempdisk-bootstrap as a small bootstrap script + systemd unit that automatically sets up the right directories under /mnt each time the VM boots. It makes sure that Nginx, PHP, ASP.NET Core, and WordPress always have the proper temp/cache directories ready to use. Here’s what it creates:

  • /mnt/nginx/fastcgi/ – Nginx FastCGI cache
  • /mnt/nginx/proxy/ – Nginx reverse-proxy cache
  • /mnt/nginx/temp/ – Nginx temp files
  • /mnt/php/sessions/ – PHP session files
  • /mnt/php/uploads/ – PHP upload temp dir
  • /mnt/dotnet/temp/ – .NET temporary path
  • /mnt/wordpress/ – WordPress export/cache files

The script handles ownerships and permissions, and it ensures that the directories are recreated after each reboot (because remember, the Azure ephemeral disk gets wiped). No more manual work, no more “file not found” errors.

Why does it matter?

Because you want your caches and temp files on the fastest disk available. By default, they usually sit on your managed OS/data disk, which is slower and more expensive. Moving them to the ephemeral disk means:

  • Faster page loads for cached requests
  • Less pressure on your main disk (and fewer IOPS throttling issues)
  • Better overall performance with zero cost

Of course, this disk isn’t persistent – so don’t store databases or critical logs there. But for temp stuff, it’s basically free performance.

How to get it

The project is available on GitHub, where you can download the latest release as a .zip and drop the files into place.

There’s also a full installation guide in the repo, but here’s the short version:

That’s it – from now on, each time your VM reboots, the right directories will be recreated and ready to use.

Nginx configuration: manual vs. semi-automatic

There are two ways to configure Nginx to use the temp disk:

Manual configuration (for complex setups)

If you run multiple sites with different caching needs, you’ll want to edit your server { } configs directly and point each site’s proxy_cache_path and fastcgi_cache_path to the proper directories. That gives you full flexibility to tune each cache zone.

Semi-automatic configuration (simpler setups)

If you just want to get started quickly, the repo includes a conf/nginx/azure-tempdisk-cache.conf file you can drop into /etc/nginx/conf.d/. It sets up sensible defaults for proxy and FastCGI caches on /mnt. Perfect if you’re hosting a few sites with similar needs.

PHP and .NET

For PHP, all you need to do is set the following in your php.ini (works for PHP-FPM and any other SAPI):

For .NET apps, just point the TMPDIR environment variable to /mnt/dotnet/temp in your systemd unit. That’s it.

FAQ: Why a systemd service instead of a simple startup script?

One of the most common questions is: why did we choose to provide a dedicated systemd service instead of just adding the bootstrap script to rc.local, cron @reboot, or similar mechanisms?

The answer comes down to reliability and timing:

  • Mount timing
    On Azure, the ephemeral disk (/mnt) is mounted by the Azure Linux Agent (waagent) or cloud-init after the basic system initialization.
    If the bootstrap script runs too early, /mnt may still be empty (or just a plain directory), and the whole setup would silently fail.
  • Explicit dependency management
    With systemd we can declare RequiresMountsFor=/mnt and After=local-fs.target, ensuring that the service only runs once the ephemeral disk is properly mounted and available.
  • Idempotence & safety
    The service runs in oneshot mode and exits after creating directories and permissions. systemd guarantees that it is executed exactly once per boot and in the correct order.
  • Integration with other services
    By declaring Before=nginx.service (or other services), we ensure that Nginx, PHP-FPM, or .NET apps never start without their required temp/cache directories being present.
  • Maintainability
    Using systemd keeps everything in the same place as other system services, making it easy to check logs with journalctl, enable/disable the bootstrap, or update the script.

In short: a plain script at boot time is fragile because it might run before /mnt is ready. A dedicated systemd unit makes the setup predictable, reliable, and fully integrated into the Linux service lifecycle.

Wrapping up

I built azure-tempdisk-bootstrap because I wanted a simple, reliable way to automatically leverage Azure’s ephemeral disk for my web workloads. It turned out to be so useful that I decided to open-source it. If you’re running Nginx, PHP, WordPress, or .NET on Azure, I think you’ll find it handy too.

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.