Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
VGSources
Blog

How to Migrate a WordPress Site from Apache to Nginx Without Breaking Permalinks

A practical Apache-to-Nginx WordPress migration runbook covering backups, PHP-FPM, rewrite translation, URLs, HTTPS, validation, DNS cutover, troubleshooting, and rollback.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The safest Apache-to-Nginx WordPress migration is a staged replacement, not a file copy followed by a DNS switch. Back up the complete WordPress directory and database, recreate Apache’s redirects and rewrite behavior in an Nginx server block, connect Nginx to a compatible PHP-FPM service, test through a temporary route, and keep Apache ready for rollback until real traffic and scheduled jobs are healthy.

What changes when WordPress moves to Nginx

WordPress itself is portable between web servers, but Apache and Nginx apply configuration differently. Apache can read per-directory .htaccess files at request time. Nginx has no directory-level equivalent, so rules that were previously hidden in .htaccess must be written explicitly in the Nginx server configuration. WordPress cannot generate those Nginx rules automatically.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Most WordPress Nginx deployments also separate the web server from PHP execution. Nginx serves static files and forwards PHP requests to PHP-FPM through a Unix socket or TCP listener. The central WordPress permalink fallback is:

try_files $uri $uri/ /index.php?$args;

This sends a request for a real file or directory directly to that resource and routes everything else to WordPress’s front controller. A successful migration therefore has to preserve more than the document root: database contents, uploads, plugin and theme code, URL settings, TLS behavior, redirects, scheduled work, and administrative access all need deliberate checks.

Plan the migration and freeze changes

Inventory the Apache site

Before installing anything, make a written inventory of the running site. Record the Apache virtual-host configuration, document root, PHP version and required extensions, database host and credentials, cron or scheduled tasks, TLS certificate and chain locations, redirects, caching layers, firewall rules, and DNS records. Note whether a proxy or load balancer sits in front of Apache; that affects client-IP and HTTPS headers after the move.

Copy the current hostname list, including the canonical host and any www variant. List every special path handled by Apache: language prefixes, feed or sitemap rewrites, legacy URLs, protected directories, image-processing endpoints, API routes, and redirects from old campaigns or product pages. These become explicit Nginx locations or redirect rules rather than assumptions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a short content freeze

Announce a maintenance window or a brief content freeze. Posts, comments, orders, form submissions, media uploads, and plugin settings written during a final database export can otherwise be missed. Keep the existing Apache site serving traffic while you prepare the Nginx copy, but stop writes for the final export and synchronization.

Back up files and the database

What the backup must contain

Create a restorable copy of the entire WordPress directory, not only wp-content. Include core files, wp-config.php, plugins, themes, and the complete wp-content/uploads tree. Export the complete WordPress database, including tables created by plugins. WordPress’s migration guidance specifically calls out the directory, images, plugins, themes, and database.

Keep the original Apache installation online and store a second backup copy on separate physical media, such as a portable external SSD. A backup is useful only if it can be read and restored, so inspect the archive, verify that uploads and custom themes are present, and perform a test database import into an isolated database or staging environment when possible.

Record a rollback point

Label the file archive and database export with the time they were made. Record the database host, name, user, and site URL associated with that point. Do not overwrite the last known-good Apache copy while testing Nginx. If a critical defect appears after cutover, the rollback plan is to route traffic back to Apache and, if necessary, restore that database snapshot before investigating further.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Provision Nginx and PHP-FPM

Prepare the target host

Install Nginx and a PHP-FPM release compatible with the existing WordPress core, themes, and plugins. Match required PHP extensions rather than assuming that the new host has the same modules as Apache. Create the target document root, copy the verified files, and restore ownership and permissions appropriate for the Nginx and PHP-FPM service accounts. Avoid making the whole tree world-writable; writable locations should be limited to those WordPress and its plugins actually need.

Create a database and user on the target server, or intentionally reuse the existing database endpoint if it remains reachable and protected. Confirm the PHP-FPM Unix socket path or TCP listener before writing the Nginx configuration. A common example socket is /run/php/php8.3-fpm.sock, but the path and PHP version must match the service installed on your host.

Confirm the application can run locally

Before DNS changes, confirm that Nginx can read the document root and that PHP-FPM can execute a harmless PHP request. Check service status and logs while loading a temporary hostname. Do not expose a diagnostic file containing environment details on the public site; remove any temporary test file after the check.

Translate Apache behavior into an Nginx server block

Minimal single-site configuration

The following pattern supplies the WordPress front-controller fallback and sends PHP files to PHP-FPM:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php;

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

    location ~ .php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
}

Replace the root, hostnames, and socket with your values. The try_files $uri =404 guard prevents Nginx from passing nonexistent script paths to PHP-FPM. Validate the syntax with nginx -t before reloading Nginx. Add HTTPS listeners, certificate paths, upload limits, security restrictions, caching, and application-specific redirects only after this basic path serves the site correctly.

Recreate every important .htaccess rule

Read the old Apache configuration and all relevant .htaccess files line by line. Translate canonical-host redirects, old URL redirects, blocked files, cache rules, and special rewrites into Nginx directives. A rule that is not copied does not continue to exist merely because the WordPress files were copied. Test each redirect with a command-line HTTP client or browser and check for loops before sending production traffic.

Multisite and unusual layouts

A multisite network, subdirectory installation, domain mapping, or custom front controller needs a configuration tailored to its paths. Do not apply the single-site block unchanged. Map each network hostname and upload path, and verify that the database’s site and network URL values agree with the requested host.

Restore WordPress configuration and database details

Review wp-config.php

Restore the database and files, then open wp-config.php on the target. If the database was moved, renamed, or assigned a different user or host, update DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. Preserve salts and other application constants unless you deliberately intend to rotate them; an accidental salt change logs every user out.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check that table prefixes, trusted proxy settings, debug settings, and any custom constants still match the target environment. Keep production debugging disabled unless you are temporarily diagnosing a controlled failure, and never display database credentials or stack traces to visitors.

Keep URLs unchanged when possible

If the domain, scheme, and path remain the same, copying the files and database normally avoids a URL migration. You still need to test redirects and generated links because server rules can change behavior even when the stored values do not.

Change URLs carefully when required

If the domain or installation path changes, update WordPress Address and Site Address in Settings → General or in the database. Confirm both values, including the https scheme and trailing path, before testing login and redirects. Search theme templates, plugin settings, widgets, JavaScript, and custom code for hard-coded references to the old URL.

Do not run a blind text replacement across the database. WordPress stores serialized PHP data whose lengths must remain valid; a naïve replacement can corrupt widget, theme, and plugin settings. Use a serialization-aware migration method and take a fresh database backup immediately before changing URLs.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recreate HTTPS, proxy headers, and redirects

Build the HTTPS listener

Configure an Nginx HTTPS server block with the certificate, private key, and complete certificate chain required by your certificate authority. Add an HTTP-to-HTTPS redirect and choose one canonical host, such as either the bare domain or its www form. Recreate every legitimate Apache redirect, including old post slugs and retired sections, before cutover.

Handle a proxy or load balancer correctly

If a proxy or load balancer remains in front of Nginx, verify how it communicates the original scheme and client address. Configure trusted handling for X-Forwarded-Proto so WordPress does not generate HTTP links behind an HTTPS proxy or redirect an HTTPS request repeatedly. Do not trust arbitrary forwarded headers from the open internet; accept them only from the known proxy path.

Check for mixed content

After enabling HTTPS, inspect pages, stylesheets, scripts, images, embeds, REST responses, and AJAX calls for HTTP references. Correct stored URLs and theme or plugin settings rather than masking the problem with a broad, untested rewrite. Confirm that the certificate is valid for every hostname users can reach.

Validate Nginx before changing DNS

Use a temporary hostname, a local hosts-file entry, or an internal load-balancer route that reaches Nginx while the public DNS still points to Apache. Test as both an anonymous visitor and an administrator.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Front-end and permalink checks

  • Load the homepage and representative posts, pages, categories, tags, author archives, search results, feeds, and XML sitemaps.
  • Open pretty permalinks with and without trailing slashes and confirm that each canonicalizes once.
  • Request a known static file and a deliberately missing path; the missing path should reach WordPress’s 404 handling rather than expose a directory listing.
  • Check robots.txt, canonical tags, pagination, and any language or custom URL prefixes.

Administration and media checks

  • Sign in through /wp-login.php and open /wp-admin/.
  • Upload a new image, generate a thumbnail, and view media from the editor.
  • Open plugin and theme administration screens, especially those that make AJAX or REST requests.
  • Verify that scheduled publishing, comments, form submissions, and outgoing email still work.

Infrastructure and security checks

  • Review Nginx access and error logs and PHP-FPM logs while exercising the site.
  • Test REST API endpoints, admin-ajax requests, cron execution, cache purges, and large uploads.
  • Check certificate validity, HTTP-to-HTTPS and canonical-host redirects, security headers, and mixed-content warnings.
  • Confirm firewall rules, rate limits, file permissions, and backup jobs on the new host.

If WordPress Address or Site Address changed, revisit Settings → General and test a fresh private-browser session. A cached login or redirect can hide an incorrect stored URL.

Cut over with a tested rollback

  1. Lower DNS TTL in advance. Do this before the maintenance window if DNS will change. A lower TTL cannot force every resolver to refresh immediately, but it reduces the expected caching period.
  2. Start the freeze. Put the site in maintenance mode or otherwise stop writes. Disable jobs that could modify the database during the final copy.
  3. Export the final database. Take a final export after the freeze and import it into the Nginx database. Synchronize files changed since the first copy, especially uploads.
  4. Run the final smoke test. Through the temporary route, test login, representative content, uploads, forms, redirects, HTTPS, and scheduled-task connectivity.
  5. Switch traffic. Point DNS or the load balancer at Nginx, then watch access and error logs for requests from real users.
  6. Keep Apache available. Do not decommission the old service or delete the verified backup immediately. Retain both until traffic, logs, orders, forms, and scheduled jobs remain healthy for an agreed observation period.

If a critical check fails, route traffic back to Apache. Restore the last known-good database only when the failure may have written incompatible data, then correct the Nginx configuration and repeat the staged tests before trying again.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot the failures that appear most often

Every post returns a 404

Check that the location / block contains try_files $uri $uri/ /index.php?$args;, that the server root is the directory containing index.php, and that Nginx loaded the intended server block. A stale or conflicting virtual host can make a correct configuration appear ineffective.

PHP downloads or returns a 502 error

Confirm that the PHP location matches .php requests, the script file exists, and the fastcgi_pass socket or TCP address is reachable by Nginx. Check PHP-FPM’s log for startup or permission failures, then reload Nginx only after nginx -t succeeds.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Login loops or redirects to the old domain

Inspect WordPress Address and Site Address, hard-coded theme or plugin URLs, cookie-domain settings, and proxy HTTPS handling. Clear application and browser caches after correcting the stored values. A loop often means WordPress sees HTTP while the visitor used HTTPS.

Images or uploads fail

Verify that wp-content/uploads was copied, the PHP-FPM process can write where WordPress expects, and Nginx’s request-body limit permits the file size. Check the error log for permission and size-limit messages rather than increasing limits blindly.

REST, AJAX, or cron requests fail

Look for an omitted rewrite, blocked location, incorrect HTTPS detection, or a redirect that changes the request method. Test the endpoint directly, inspect the response status in the browser’s network panel, and compare the request path with the old Apache behavior.

Choose the right operating model

A self-managed Nginx server provides direct control over server blocks, PHP-FPM, TLS, firewall rules, caching, and deployment timing. That control also makes you responsible for patching Nginx, PHP-FPM, the database, certificates, backups, monitoring, and rollback drills.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Managed WordPress hosting can remove much of that maintenance, but the host must explicitly support Nginx and PHP-FPM and provide a documented process for backups, staging, migrations, TLS, redirects, and custom server rules. WordPress advises managed-hosting customers to consult their host before changing server configuration. Ask who owns the database export, how quickly a previous version can be restored, and whether a temporary test hostname is available.

Decision axis Self-managed Nginx Managed environment
Operational control You edit server blocks, PHP-FPM settings, TLS, firewall rules, and cache policy. The host controls the platform; custom directives may require support approval.
Compatibility work You translate every rewrite, redirect, PHP setting, and proxy rule. The host may provide migration tooling, but you must verify its Nginx behavior and exceptions.
Rollback speed Depends on your accessible file and database backups and DNS or load-balancer control. Depends on the provider’s restore points, staging workflow, and support response.
Traffic handling You design direct Nginx service or Nginx behind a proxy or load balancer. The provider defines the front-end topology and forwarded-header behavior.
Maintenance burden You patch Nginx, PHP-FPM, TLS, the database, and WordPress. The host may patch infrastructure, while you still maintain WordPress, plugins, themes, and content.

What this migration can and cannot prove about performance

Changing Apache to Nginx may alter resource use, concurrency behavior, caching options, or operational workflow, but the implementation guidance available for this procedure does not establish an authoritative speed improvement, downtime figure, migration duration, or success rate. Treat performance as a measurement task: establish a baseline, repeat the same representative requests after cutover, and account for PHP version, plugins, database load, cache state, network path, and proxy configuration. Do not promise a numeric gain solely because the web server changed.

Final readiness checklist

  • Complete file archive and database export have been inspected and stored separately.
  • Apache remains available as the known-good rollback target.
  • Document root, PHP version and extensions, database details, cron, TLS, redirects, cache, firewall, and DNS behavior are documented.
  • Nginx syntax passes validation and PHP-FPM receives only valid script paths.
  • WordPress Address and Site Address are correct, and serialized data was migrated safely if URLs changed.
  • Permalinks, uploads, admin screens, REST, AJAX, forms, email, cron, HTTPS, canonical redirects, robots.txt, and security headers have all been tested through a temporary route.
  • Final database and file synchronization occur during a controlled freeze.
  • Monitoring, DNS or load-balancer access, and a written rollback procedure are ready before traffic moves.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.