When browsers go to a site, the browser sends a request to the site’s web server. The web server stores all the site’s information (like HTML and image files) and will give the browser what it needs to load the site. By owning a hosting account, you are given access to a web server. The files you add to the hosting account to create your site are the ones shared with the browsers so that they can display the site. This may seem like a simple process, but the web server requires a complex system to make this work.
Web servers have to work with the modern operating systems, like Windows or Unix. It also has to be efficient and meet current HTTP standards.This is where Apache and Nginx come in. Both Apache and Nginx are open-source web servers that have been created to function under all these requirements.
What is Apache?
Apache was created over 20 years ago, but has continued to still be relevant and very much used today. Even though it is over 20 years old, the web server has been upgraded to handle the new needs of the modern-day website. If you’re interested, though, here’s how Apache started out:
Evolution of Apache: 1995 to 2018
The Apache of 1995, the year it was created, was revolutionary. When a browser requested a connection, Apache would see the connection request, send a response, then quit. As time went on, Apache added multiple processes to field incoming requests, thus speeding up the time it took for browsers to hear back from the server. These processes would take each new connection request as they came in so that multiple requests could be answered at once. If all the processes were in use, new processes would be created.
The internet continued to grow at a rapid rate, though. With more traffic and web pages becoming larger and larger, browsers were starting to request multiple connections where a single connection would have sufficed before. Instead of falling out-of-date, however, Apache grew to accommodate the new normal. It implemented a new, lighter process equivalent. It was called threads and could handle more connections than the previous set up.
What is Nginx?
Nginx, on the other hand, was actually created as a way to aid Apache with high traffic. However, while it originated as an Apache addition, it soon developed functionality as its own stand-alone server. It still retains the functionality to be used as a front-end proxy for Apache or other web servers.
Nginx was specifically designed for high traffic situations when many different connections were being requested at once. It uses a main thread that enables worker processes to meet many different requests. Nginx also proxies out many of its processes so that it is able to devote power to making quick connections. Proxying out processes is like outsourcing the work – Nginx sends processes it doesn’t want to handle itself, like PHP, to other systems that will do the work for it. This leaves Nginx to focus on other processes.
Which One Should I Use?
Nginx and Apache are very popular for open-source web servers. You can actually use Nginx in conjunction with Apache. However, if you don’t want to use them together, which one should you use?
Well, it depends on what you’re looking for. Both are great web servers, but here are some things to consider to find which one works best for you:
Apache allows you have .htaccess. Apache’s ability to process PHP internally allows users to use make modifications using PHP. An .htaccess file gives you extra control over your directories and can be used to issue directory-specific commands. Since Nginx proxies out its PHP processes, it doesn’t allow for PHP that would need to be processed internally, such as .htaccess or mod_php.
Nginx runs a little faster because it proxies out. While Apache can handle PHP internally without proxying out, Nginx runs a bit faster because it doesn’t have to run those processes or analyze directories for any .htaccess files.
Apache is easier to add user-made customizations. This also comes back to Apache’s ability to internally process PHP. In Nginx, customizations need to be done in the actual Nginx configuration, while Apache allows for things to be tweaked through .htaccess files.
Choosing a web server may depend on what you want to do with it. You can choose Apache and be able to use internal PHP, like .htaccess and mod_php. This makes tweaking your server easier, but can also potentially slow your web server slightly. Nginx, on the other hand, doesn’t have access to these easy customizations but may run slightly faster than Apache.
So if you can visualize yourself as someone who makes a lot of server customizations on the fly, you may want to choose Apache. On the other hand, if you don’t think you’ll need to make any changes, Nginx may be more your speed.
If you liked this article, you can subscribe to get updates when new articles launch.