Migrating from Apache to NGINX, possible limitations


We currently have a Virtualmin Professional installation with about 165 Websites all running on Apache 2.4.37, PHP 7.2.14, and MariaDB 10.2.22, almost all of which use WordPress to power the Website. In addition, we have the Varnish cache server set up on port 80 and Apache on ports 8080 and 443, and SSL termination is handled by Apache so that Virtualmin can work its existing Let's Encrypt magic and then proxy requests (using Apache) from 443 to Varnish on port 80.

While this setup works, and is split across five different Web servers that all share home directories, Postfix and Dovecot configuration files, and other data, and are sitting behind a single load balancer, memory use on each machine is quite high out of a total of 8 GB RAM per machine, and thus for this reason and several others I am looking into switching from Apache to NGINX.

I have read all over the place on Virtualmin.com that it is recommended to use a fresh, newly-installed copy of Virtualmin when beginning an NGINX journey, but instead I am looking into ways to migrate our existing Websites (both SSL and non-SSL) from Apache to NGINX, preferably the virtual host configuration files and other things used by Apache.

Is this possible and could it perhaps be automated somehow so that we don't have to do this by hand to all 165 sites? At this point I don't care about downtime as we have a separate machine we use for testing and stuff that we could always backup and restore onto our production machines once everything is in place. But I am really looking hard at NGINX, and I've heard Virtualmin's support for it has improved greatly over the years, so I wanted to throw out this migration scenario to see what route I should take moving forward, or if it's even practical/possible given our current setup. Any insight or assistance you could provide would be very much appreciated. Thank you!



only 8 gigs per machine? I would at the minimum double it. My lowest server runs 16 and i am migrating to 24-36 gigs of ram in the coming months.

Doubling the RAM would be nice but at this point we don't have the financial resources to be able to do so, especially as we are using Linode as our service provider and their prices get steep quite quickly. Plus, all of the important things, like Website files and MySQL databases, are hosted on other machines that do have 16 GB RAM and mounted (in the case of our GlusterFS filesystems) or configured to be used (in the case of MySQL/MariaDB) on our 8 GB Web nodes via the private network. So all the Web nodes are doing is essentially serving Web content via Apache and caching via Varnish while our backend machines do the heavy lifting.

Do you want to migrate from Apache to Nginx domain by domain on a single system? Unfortunately this isn't possible due to the way the webservers open port 80 - you'd have to do the whole system in one go.

Well, right now we have Virtualmin set up on only one of the machines in our Web cluster; the others mount the same filesystems Virtualmin has access to for things like home directory sharing, Postfix/Dovecot, etc. but everything is "controlled" from the Virtualmin system. Varnish is running on port 80 right now so NGINX would have to use 8080 and 443 which is currently what Apache is using. I didn't quite understand the part of your message about how Web servers open the port though, what did you mean by that? Would a global migration be possible as opposed to domain by domain? Or could we back up Virtualmin and restore it on a Virtualmin system that has NGINX configured instead of Apache, like would Virtualmin just recognize this and rewrite things during restore?

Yes, a global migration would be possible. Basically, you could do the following :

  1. Disable the Apache feature for all domains.
  2. Turn off Apache globally on the Features and Plugins page.
  3. Shut down Apache webserver, and install and start Nginx.
  4. Enable Nginx on the Features and Plugins page.
  5. Enable the Nginx feature for all domains.

The down side though is that any custom apache settings, redirects or PHP versions will be lost.

How will the steps you outlined affect alias/sub-servers?

They will be preserved as they were before.

Oh good. One other question, right now all virtual servers use mod_fcgid. How would this translate over to NGINX?

Any update on this?

The PHP execution mode will be whatever is the default, which is typically mod_fcgid.

OK. I guess my next question here is, 95% of the sites we host under Virtualmin are WordPress installations with .htaccess files that WordPress writes automatically based on permalink settings and other such options. How would these work under NGINX?

they should work fine..the .htaccess thing is not specific to apache. if you get php to run under nginx then WP and other php based scripts should run jsut fine as well.

Pardon my possible ignorance but how is .htaccess not specific to Apache? I mean the directives inside directly correlate to Apache-specific features and modules like mod_rewrite.

nopers i sit corrected...:) nginx does not suport .htaccess at all. Those directives have to be put under nginx.conf or something similar. I ma not sure how virt can use nginx in a shared hosting environment...The sites that say they support nginx offer nginx on vps..meant for a single site. I saw a guide to running nginx in a shared environment for ubuntu 14.x....

Hmm, I mean if Virtualmin has support for NGINX I would think their implementation would be built to support shared hosting since Virtualmin is after all a shared hosting platform...can one of the Virtualmin devs chime in on this?