From Apache to Nginx

When I initially setup my VPS to self-host a few things, this blog included, I used Apache HTTP Server. Why? Because it's really the only one I've ever used and played around with. So it was just a familiarity thing. I started playing around with web development and web hosting somewhere around 25ish years ago. Right around the time I was getting out of high school. According to Wikipedia, "At the end of 1996 there were already over fifty known web server software programs". I honestly never knew there were so many and have probably only ever heard of a few of them at most. My understanding over the years as a hobbyist was that Apache HTTP Server ran the vast majority of the internet. Reading through the Wikipedia entry linked above about the history of web servers, I see that Apache was initially king, gave way to IIS for a brief period before surging back up some, but now Nginx looks to be the reigning current champ. As someone who is a simple hobbyist and not a web server administrator by trade, I rely heavily on those with far more expertise to provide configurations that are safe and secure to use and not just try to come up with configurations all on my own.

My recent foray into setting up a Calckey instance has resulted in me attempting to utilize Apache for a piece of software where the developer only provided an Nginx configuration - who also strongly advised against using Apache for both performance and functional reasons. While I was able to create a functional reverse proxy with Apache to serve up the Calckey interface, there seemed to be quite a few background update type things that were not functioning. So I was faced with two options. Continue to use Apache and try to figure out how to migrate the default Nginx configuration over to Apache to achieve the same functionality. Or finally break down and switch to Nginx so I could use the recommended configuration.

I ultimately decided to go with the former and migrate my VPS over to Nginx from Apache. And all in all, it wasn't as difficult as I had imagined it would be. After initially getting Nginx running in parallel to Apache on a different port to test a few things out, I dove in and shutdown Apache and had all of my hosted sites back up and running in an afternoon.

I don't really know a ton about Digital Ocean overall, but from the bits and pieces I gather reading about around the internet, they seem to be a fairly well liked service provider for VPS and hosting services. I will say, they have a LOT of great tutorials that can help guide people through a lot of VPS and self hosting adventures. I often find myself at their site following along to one of their tutorials. I began my process following along with this aptly named tutorial How to Migrate from an Apache Web Server to Nginx on an Ubuntu VPS.

Once I had gotten Nginx running in parallel on a different port and proved to myself that I could serve up a couple of my services with Nginx, I decided to just pull the plug, kill apache, and run with Nginx. All in all it took me a handful of hours to go through this whole process and I had all of my services (except one) back up and running.

All in all I have 5 services running on my VPS:

  1. Textpattern (This Blog)
  2. Nextcloud
  3. Calckey
  4. Gitea
  5. Miniflux

Miniflux is the aforementioned 'except one'. Not because I couldn't get it to work with Nginx, I just haven't bothered yet. Wasn't a priority because I haven't really been using it lately.

The Digital Ocean tutorial really gave me everything I needed to get Nginx up and running, do the basic configuration, and get my feet wet. I don't really have much of anything to add to that.

Calckey was really what drove me to make the switch. And the Nginx configuration provided with the rest of the Calckey software in the git repo was all I needed to use. As soon as I had it up and running with the Nginx config, all of the issues I was seeing with my Apache configuration were gone.

Nextcloud provides Nginx configurations. And boy are they long (maybe not THAT long, but by far the longest Nginx conf I've worked with yet). Often times when I'm working with an example from somewhere, I prefer to type it out rather than copy/pasting it. I do this as a bit of a learning exercise to help me (maybe) learn a bit and get a better understanding of what's going on. The downside of this is that I often introduce typos. Which is what happened here and had me scratching my head for a period of time. Once I got that sorted out, Nextcloud was functioning fine. There were a couple php related items I needed to tweak that the Administrative Security and Setup Warnings page notified me about. This was because in switching to Nginx, I also switched to the latest PHP-fpm software as well, which has a different configuration than what I was using with Apache. There are a couple more items showing on that page that I need to look at a bit further and resolve, but for the moment, everything appears to be working just fine.

Gitea provides a very simple reverse proxy Nginx configuration in their documentation. No problems at all with this.

As expected, Textpattern also provides an Nginx config. Here is where I ran into an odd problem. The main site worked perfectly fine, but on the admin panel side, CSS was not being loaded. In the Firefox inspector panel, I was seeing an error stating that the CSS file couldn't be loaded due to an incorrect mime-type. It was showing up as text/plain instead of text/css and Firefox was not happy about that. I did not actually test this in other browsers. By default, it seems that the admin panel pages seem to be missing the type declaration in the link stylesheet line. I'm assuming that I could probably fix that there as well, but instead I opted to add the following to the Nginx configuration file for my Textpattern site:

location ~ \.css {
    add_header Content-Type        text/css;
}

This resolved the issue. I believe what this is doing is any CSS file that is requested is appended with the proper text/css mime-type.

And that's it. The point of this little write-up is to say that if you're considering switching from Apache to Nginx, and you're nervous about it, there's a good chance it's not going to be as bad as you think. At least, that was my experience. I really thought I was going to make a mess of things and wind up having to nuke my whole VPS and start over (I have a tendency to way overthink things). But it really was not that bad at all. A bit of reading and playing around for a few hours and I was all finished.

Good luck.

  1. Previous Post
    Contributing. A Git Tutorial.
    Mon, Dec 19, 2022
    Tutorials Git
    A tutorial to help get started using git to contribute to an open source project.
  2. Next Post
    ssh-askpass Frustration
    Thu, Dec 28, 2023
    Troubleshooting ssh-askpass Arch Linux Wayland
    Some notes on what finally worked for me when I ran into trouble with ssh-askpass.