Web programming

Differentiate between nginx and apache

Ngoc Phuong

Ngoc Phuong

2020-03-04 . 65 view

Nginx and Apache are currently the two most popular web servers. The web server market changes daily, with Apache gradually losing ground, while Nginx, apart from catching up with Apache, is now the choice of many high-traffic websites. Has Apache become outdated? To understand this issue more clearly, please refer to my article below.

I. Understanding Web Server?

1. What is a Web Server?

A web server is a type of server on the internet, each server having a different IP and able to read languages ​​like .htm and .html files...

Web servers can be either hardware or software, or even both.

  • Hardware: A web server is a computer that stores image files, HTML, CSS, JavaScript of a website and delivers them to the end user. Web servers are connected to the internet and can be accessed through a domain name, like kiemtientuweb.com, for example.
  • Software: A web server comprises some control software allowing user access to files stored on an HTTP server. The HTTP server is software that can understand website addresses (URLs) and the protocol browsers use to view websites (HTTP).

2. How to Publish a Website

Websites come in two types: static and dynamic.

  • To publish a static web page, you simply need a static web server consisting of a computer and an HTTP server. This is because the content of static web pages does not change when the web server sends it to the end user.
  • To publish a dynamic web page, a static web server needs some special auxiliary software, the most common being an application server (application server) and a database. We call it dynamic because the application server updates the stored files before sending them to your browser via the HTTP server.

3. Web Server Processing

When you need to access a web page, your browser sends a request to the server. The web server processes and searches for the requested file in its memory. In finding the file, the server reads this file, processes it if necessary, and then sends it back to the browser.

4. Steps to retrieve data from a website

Step 1: Web server hosts the website's files - File Hosting

The Web Server must be where all the files of the Web pages or the source code of the Website are stored.

Technically, you could store all these files on your personal computer or laptop to make it a Web Server, as long as you install and ensure the following factors:

  • Always running and operating continuously.
  • Always connected to the internet.
  • Always maintain a single IP address.
  • Be maintained by a third party.

As these requirements could be quite difficult for an individual, various Hosting, VPS providing services have emerged as a result.

Step 2: Communicate via HTTP

The web server supports the Hypertext Transfer Protocol - HTTP. HTTP is a set of rules for connecting two computers consisting of Textual and Stateless.

  • Textual: All commands are pure text and can be read by the user.
  • Stateless: When both the user and the server do not remember the previous connection.

HTTP has clear rules for communication between the client and server as follows:

  • Only the client can generate an HTTP request to the server. Servers can only respond to the client's HTTP request.
  • The client must provide the URL of the file when requesting that file via HTTP.
  • All incoming HTTP requests will be answered by the web server.

HTTP has a responsibility to process and respond to incoming requests through several steps:

  • Upon receiving a request, HTTP will check if the requested URL matches an existing file.
  • If matched, the web server will send the file's content back to the browser. In case of mismatch, an Application server will generate the requested file.
  • The web server will send an error message back to the browser (most commonly '404 Not Found') if it cannot process the request.

II. Popular Web Servers Today

1. Apache

1.1 What is Apache?

Apache (HTTP server program) Full name is Apache HTTP Server. It's an open-source server that is free and widely used now. The Apache server is developed and operated by the Apache Software Foundation.

Apache HTTP server program is a server-specific program that communicates via the HTTP protocol. Apache runs on operating systems similar to Unix, Microsoft Windows, Novell Netware and others.

Apache works well with both Unix and Windows servers and is cross-platform software.

1.2 How does Apache work?

Apache's job is to establish a connection between the Server and the Web browser (Firefox, Chrome, Safari,...), it's responsible for transferring files back and forth between the Server and the Web browser (two-way client-server structure).

1.3 What features does Apache have?

Apache has the following features:

  • Static file serving
  • SSL/TLS support
  • Virtual hosts
  • Reverse proxying
  • Load balancing
  • Compression
  • Access controls
  • URL rewriting
  • Custom logging
  • Server-side includes
  • Limited WebDAV
  • FLV streaming
  • FastCGI
  • Digest access authentication
  • CGI
  • Administrative console
  • .htaccess

1.4 Advantages and Disadvantages of Apache

Advantages:

  • Apache is free open-source software
  • Simple configuration and friendly to those who are new to this software
  • Apache is stable and reliable
  • This software is frequently updated
  • It continually detects and reports security issues, helping users to block them in time, and preventing information theft.
  • Flexible module structuring modes
  • Apache works effectively and responsively with WordPress sites
  • The Apache user community is large so it can support and answer all questions

Disadvantages:

  • Occasionally slow or encounters hitches during a query because there are many people accessing Apache at the same time
  • The security capacity is sometimes not effective since it's free software, users can choose multiple different settings.

2. Nginx

2.1 What is Nginx?

Nginx is a renowned open-source server. When first introduced, Nginx was used to serve HTTP web. However, it is now used to perform as a Reverse Proxy, Email Proxy (IMAP, POP3, SMTP) and a load balancer and reverse proxy for HTTP, TCP, and UDP servers.

Nginx was officially launched by Sysoev in October 2004. Nginx uses an asynchronous event architecture. This feature helps Nginx speed up, expand features, and be more reliable. Many large traffic websites have used Nginx also due to its robust ability to handle thousands of connections simultaneously.

2.2 How does Nginx work?

Nginx works based on an Asynchronous and Event Driven architecture. This architecture comprises Threads that are managed within a process, each process works based on smaller entities – Worker Connections.

Worker Process will receive queries from Worker Connections and send these queries to the parent Process – Master Process. The Master Process will return the results of these requests. One Worker Connection can deal with 1024 similar requests. Thus, Nginx can handle thousands of requests without any problems.

Nginx is always more efficient when operating in search environments, e-commerce, and Cloud Storage.

2.3 What features does Nginx have?

Nginx includes the following features:

  • Ability to handle over 10,000 connections simultaneously with low memory usage
  • Serves Static Files and indexes files
  • Uses Cache memory to accelerate Reverse Proxy, simple load balancing, and fault tolerance
  • Supports acceleration with the buffer memory of WSGI, SCGI, FastCGI and Memcached servers
  • Has a flexible configuration and query logging capability
  • Redirects 3XX – 5XX errors
  • Utilizes Regular Expressions to Rewrite URL
  • Restricts the response rate to queries
  • Limits queries from a particular address or number of concurrent connections
  • Has the ability to embed PERL code
  • Compatible and supports IPv6
  • Supports WebSockets
  • Supports the transmission of MP4 and FLV files
  • Rewrite URL,…

3. Comparing Nginx and Apache

3.1 Performance

3.1.1 Static Web

Nginx is 2.5 times faster than Apache based on a benchmark test running up to 1000 simultaneous connections.

In another test with 512 simultaneous connections, Nginx is about 2 times faster and consumes less memory (4%).

3.1.2 Dynamic Web

For Dynamic Web, there is not much difference. This is because most requests being processed in the PHP runtime environment are quite similar for both web servers.

3.2 Supported operating systems

Apache works on all types of Unix-like systems (Linux or BSD) and fully supports Microsoft Windows.

Nginx also runs on a few of these systems and also supports Windows, however, its performance is not as strong.

3.3 Security

In terms of security, both take this very seriously, both often issue security reports and advisories, ensuring that security aspect is enhanced at all levels.

3.4 Support and documentation

Both Nginx and Apache provide documentation, covering most of the necessary topics and features. These documents include release notes, user guides, tutorials... Nginx even has its own wiki.

3.5 Flexibility

A web server should be flexible enough to allow for customization. Apache does this quite well, through using .htaccess tools that Nginx does not support.

Furthermore, Apache allows for admin responsibilities to be tiered. Third-party and secondary admins may be blocked from accessing the main server.

Apache also provides more than 60 modules to help make Apache highly expandable. That's why Apache is more popular with shared hosting providers.

III. Conclusion

Both the Nginx web server and Apache web server are bright candidates in various fields. Nginx is the clear winner for static content, while dynamic content doesn't make a real difference between the web servers.

Apache is more superior in terms of flexibility, especially for shared hosting users. Apache's .htaccess file and dynamic modules are definitely more suitable, while Nginx would be better for VPS and dedicated hosting.

Ngoc Phuong
Ngoc Phuong

Web Developer

Thank you for visiting my website. My name is Ngoc Phuong, and I have over 10 years of experience in website development. I am confident in stating that I am an expert in creating impressive and effective websites. If you need a website designed, please feel free to contact me via email at [email protected].

0 feedback

Related article