Switching a website between Apache and Nginx requires migrating its configuration as well as changing the running service. Both can serve websites, but their configuration formats and application handling differ.

Check which web server is currently running

On a Debian or Ubuntu server, check the relevant services and listeners:

sudo systemctl status apache2
sudo systemctl status nginx
sudo ss -ltnp

Other distributions may call Apache httpd. Both services can legitimately run together when one is a proxy.

This guide concerns a standalone server you administer. For cPanel or Plesk, use the platform’s supported web-server configuration rather than stopping its managed services independently.

Install the alternative web server

Prepare and test the replacement on staging before production cutover. On Debian or Ubuntu, the repository packages are apache2 and nginx.

Package installation can start a service automatically. Plan its listen addresses and ports so it does not conflict with the existing server.

Copy the intended site configuration, certificates, redirects, access controls and application handling. Nginx does not read .htaccess; translate required rules explicitly. PHP may require a configured PHP-FPM service.

Stop and disable the current web server

Back up both configurations and arrange downtime and recovery access. Test the replacement’s syntax before stopping the current service:

sudo nginx -t

For Apache on Debian or Ubuntu, use sudo apache2ctl configtest instead.

During the approved cutover, stop only the old service. For an Apache-to-Nginx replacement:

sudo systemctl stop apache2

Keep it available for rollback until the replacement is verified.

Enable and start the new web server

For the same example:

sudo systemctl start nginx

If it fails, stop the replacement and restore the old service before investigating. Do not leave the site without a working server.

Verify the active web server

Test every hosted domain, HTTPS, redirects, login, uploads and application connections. A default welcome page does not prove your sites migrated successfully.

After verification, set the intended startup policy:

sudo systemctl enable nginx
sudo systemctl disable apache2

Reverse the service names for the opposite migration. Keep backups and check logs after the change.