Archives
- Newer posts
- November 2024
- April 2024
- November 2023
- October 2023
- August 2023
- May 2023
- February 2023
- October 2022
- August 2022
- July 2022
- May 2022
- April 2022
- March 2022
- February 2022
- June 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- August 2016
- June 2016
- April 2016
- March 2016
- February 2016
- January 2016
- July 2015
- June 2015
- Older posts
Apache vs Nginx
A Web server is a program that uses HTTP to fetch files that form web pages and serve them to the client requesting these pages. The basic objectives of a Web Server are to store, process and deliver web pages to the users. The web server stores the HTML documents, Images, Style-sheets and JavaScript files
Apache is the most widely used web server. It is free and open source. Functionality for Apache is introduced through modules. Modules can be installed to extend the server’s capabilities. To add a new module, you need to install it and restart the Apache server. Functionality that you don’t need or want can be removed. This helps to keeps the server small, consumes fewer resources and memory, and makes the server less prone to security holes.
When a request comes in, the server does not know which module is responsible for handling a specific request and will ask each module whether they can process a request. The modules will reply and the server will assign the request to a module according to the reply given by the modules.
One server can host many websites. To achieve this, every one of those websites has to be assigned a different name, even if they map to the same machine.
NGINX is open source software. It can be used as a web server, reverse proxy, and a load balancer.
Igor Sysoev wrote NGINX to solve the C10K problem, a term coined in 1999 to describe the difficulty that existing web servers experienced in handling large numbers (the 10K) of concurrent connections (the C)
Nginx consists of modules which are controlled by directives. Directives can be simple directives and block directives. A simple directive consists of the name and parameters separated by spaces and ends with a semicolon. A block directive has the same structure as a simple directive, but instead of the semicolon, it ends with a set of additional instructions surrounded by braces ({ and }). If a block directive has other directives inside braces, it is called a context
Events Context: The “events” context is used to set global options that affect how Nginx handles connections at a general level. There can only be a single events context defined within the Nginx configuration.
HTTP Context: HTTP context is contained within the “main” context. This context will contain all of the directives and contexts necessary to define how the program will handle HTTP or HTTPS connections.
Server Context: The “server” context is declared within the “HTTP” context. It allows for multiple declarations. The reason for allowing multiple declarations of the server context is that each instance defines a specific virtual server to handle client requests.
Nginx has one master process and several worker processes. The master process can read and evaluate configuration, and maintain worker processes. Worker processes do the actual processing of requests.
Apache uses .htaccess files for directory-specific configurations in the directory that houses the files. Nginx does not allow these files as it causes security problem if misconfigured. As a result, all configurations defined in a .htaccess file must be placed within the location block in the server context.
Apache has many functionalities but it takes up a lot of memory. Nginx is more secure and faster than Apache, however, it cannot do any processing on its own. You can have Apache and Nginx working together on the same server to leverage each server’s strengths, but you can’t have them listening on the same port.
Nginx is in the front, listening on port 80. Nginx accepts user connections and can act as what is referred to as a reverse proxy. A reverse proxy will pass requests through Nginx to your backend server. This can be your Apache server. Nginx is fast for serving static content, if the request is only for static data, Nginx will serve the request. If any processing needs to be done, the request will be forwarded to Apache server. Apache server will do all the processing and return the reply back to Nginx, which will then send the reply to the client.