Docs / Migration Guides / How to Migrate from Apache to Nginx Step by Step

How to Migrate from Apache to Nginx Step by Step

By Admin · Mar 1, 2026 · Updated Apr 23, 2026 · 27 views · 2 min read

Migrating from Apache to Nginx can improve performance and reduce memory usage, especially for high-traffic sites. This guide covers the key steps for a smooth transition on your Breeze.

Step 1: Audit Your Apache Configuration

List all active virtual hosts and modules:

apachectl -S
apachectl -M

Note down each virtual host, rewrite rules, and any .htaccess directives you rely on.

Step 2: Install Nginx

sudo apt update && sudo apt install -y nginx
sudo systemctl enable nginx

Step 3: Convert Virtual Hosts

Translate Apache VirtualHost blocks to Nginx server blocks:

server {
    listen 80;
    server_name example.com;
    root /var/www/example.com/public;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Step 4: Convert Rewrite Rules

Apache mod_rewrite rules translate to Nginx rewrite or try_files directives. Common conversions:

  • RewriteRule ^(.*)$ /index.php [L] becomes try_files $uri $uri/ /index.php
  • RewriteCond %{HTTPS} off becomes a separate server block with a 301 redirect

Step 5: Swap and Test

sudo systemctl stop apache2
sudo nginx -t && sudo systemctl start nginx
curl -I http://example.com

Rollback Plan

Keep Apache installed but stopped until you confirm everything works. You can quickly revert by stopping Nginx and restarting Apache if needed.

Was this article helpful?