Nginx is a type of open-source software. This type of software is used for web serving, reverse proxying, load balancing, media streaming, Image caching, etc. The software was written by Igor Sysoev who was a Russian Engineer. Igor Sysoev started to write this software in 2002 and the software was published in the year 2004. Nginx is used for high-performance and scalable websites. Nowadays over ten million active websites use the Nginx software.

Some of the companies that use the Nginx software are Airbnb, Dropbox, Netflix, Tumbler, and WordPress.com. All these companies are the most reputed and well-known companies in the world. Numerous types of Nginx interview questions and answers will help you a lot.

Nginx is best known for its performance, stability, rich feature set, simple configuration, and low resource consumption. This software was mainly created to solve the problem of the CK10. Below are some of the Nginx interview questions and answers from which you will know better.

Theoretical Questions

1. What is Nginx?

Nginx is a type of open-source web server that is especially used for reverse proxy, load balancer, mail proxy, and the HTTP cache. Nowadays NGINX software is most commonly used by various companies. NGINX can run on Linux, Mac OS X, Solaris, AIX, HP-UX, and the BSD variants. Nginx was initially released on 4 October 2004 and written in C programming language. It is pronounced as “engine x“.

2. What are the webserver, load balancing, image caching, reverse proxy, backend routing, and forward proxy?

  • Web server: A web server is a software and hardware that uses HTTP (Hypertext Transfer Protocol) and other protocols to respond to client requests made over the World Wide Web. The main job of a web server is to display website content through storing, processing, and delivering web pages to users.
  • Load Balance: In computing, load balancing refers to the process of distributing a set of tasks over a set of resources, with the aim of making their overall processing more efficient.
  • Image Caching: Image caching is a process where images are stored inside the client’s system to load the application faster. Nginx stores Website images in the client system to load the application faster.
  • Reverse Proxy: A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server.
  • Backend Routing: In backend routing, the server handles every request by responding to the client with a code 201(I got that thing you want!) or a 404 (Nope, I don’t have that!).
  • Forward Proxy: A forward proxy is a server where a person sends a request directly to the target server.

3. Why use Nginx?

  • Cross-platform, simple configuration, direction proxy, high concurrency connection: handles 20,000 to 30,000 concurrent connections, official monitoring can support 50,000 concurrencies, low memory consumption: only 10 Nginx is enabled, it takes up 150M memory, Nginx handles static files well, and costs Less memory,
  • And Nginx’s built-in health check function: If a server is down, a health check will be performed, and the request sent again will not be sent to the down server. Resubmit the request to other nodes.
  • Using Nginx can also:
    1. Save broadband: support GZIP compression, you can add browser local cache
    2. High stability: the probability of downtime is very small
    3. Receiving user requests is asynchronous

4. What are the advantages and disadvantages of Nginx?

Advantages of Nginx:

  1. Working on the 7th layer of the network, it can do some diversion strategies for HTTP applications, such as domain names and directory structures. Its formal rules are more powerful and flexible than HAProxy, so it is widely popular so far.
  2. Nginx has very little dependence on network stability. In theory, it can be pinged to perform load functions.
  3. Nginx installation and configuration are relatively simple, testing is also relatively convenient, and it can basically print out the error log.
  4. It can bear high load pressure and is stable. Generally, it can support tens of thousands of concurrency when the hardware is not bad, and the load is smaller than LVS.
  5. Nginx can detect the internal failure of the server through the port, such as the status code returned by the server processing the webpage, timeout, etc., and will resubmit the request that returned the error to another node.
  6. Not only an excellent load balancer/reverse proxy software but also a powerful web application server. LNMP is also a very popular Web architecture in recent years, and it is also very stable in high-traffic environments.
  7. It can be used as a middle-level reverse proxy.
  8. It can be used as a static web page and image server.
  9. The Nginx community is active, with many third-party modules, and relevant information abounds online.
  10. Nginx configuration is simple.

Disadvantages of Nginx:

  1. The scope of adaptation is small, and it can only support HTTP, HTTPS, and Email protocols.
  2. The health check of the back-end server only supports port detection, not URL detection. For example, if the user is uploading a file, and the node processing the upload happens to fail during the upload process, Nginx will cut the upload to another server for reprocessing, and the LVS will be directly disconnected. If it is uploading a large file Or for very important files, users may be dissatisfied.
  3. A less extensive list of modules.
  4. Poor dynamic processing: Nginx handles static files well and consumes less memory, but processing dynamic pages is very tasteless. Now generally the front end uses Nginx as a reverse proxy to resist pressure.

5. Explain how Nginx can handle HTTP requests?

Nginx uses the reactor pattern.  The main event loop waits for the OS to signal a readiness event- such that the data is accessible to readers from a socket, at which instance it is read into the buffer and processed.  A Single thread can serve tens of thousands of simultaneous connections.

6. Explain what is C10K problem?

C10K problem is referred for the network socket unable to handle a large number of clients (10,000) at the same time.

7. What are the ways to install Nginx?

  1. By Source Code(Binary)
  2. From Package Installer(Yum, Repo, APT)
  3. By Docker Image

8. What is the default Port number of Nginx?

  • For un-secured traffic, it uses Port 80,
  • For Secured traffic, it uses Port 443

Note you can change the default port in the following files:

# /etc/nginx/sites-enabled/default  [On Debian/Ubuntu]
# /etc/nginx/nginx.conf             [On CentOS/RHEL]

9. Explain how to add modules in Nginx Server?

During the compilation process, Nginx modules must be selected as such run-time selection of modules is not supported by Nginx.

10. Can we add Modules in Nginx after installation?

Yes, but for that, you need to reconfigure(compile) the Nginx.

11. Difference between Nginx and Apache Tomcat?

S.NO.ApacheNginx
1.Apache is an open-source web server.Nginx is a web server. It is also used as a reverse proxy server which revises the request from the client and sends the request to the proxy server.
2.It is mostly used for Unix, Linux, Windows, and Solaris platforms.It is mostly used for Unix-like systems and does not completely support Windows.
3.It was developed by the Apache group and initially released on 25 March 1999.It was developed by Nginx. inc and initially released on 4 October 2004.
4.Apache is written in C and XML.Nginx is written in C language.
5.It is designed for web servers.It is designed for proxy servers as well as a web servers.
6.In heavy web traffic, it cannot support multiple requests.It can support multiple client requests with limited hardware resources.
7.In Apache, modules are dynamically fixed which makes it more complex.In Nginx, modules cannot be loaded dynamically as there is a core software with which they have complied.
8.It follows a Multi-Threaded approach to processing client requests.It follows an Event-Driven approach to processing client requests.
9.In Apache, there is dynamic content in the web server itself.It does not support providing dynamic content.
10.Apache’s performance for static content is lower than that of Nginx.Nginx’s performance of static content is two times faster than that of Apache as it can simultaneously run thousands of connections and it uses less memory comparatively.

12. Explain does Nginx support compress the request to the upstream?

You can compress the request to the upstream by using the Nginx module gunzip. The gunzip module is a filter that decompresses responses with “Content-Encoding: gzip” for clients or servers that do not support the “gzip” encoding method.

Practical Questions

13. How to stop/start Nginx Server?

You can restart by going to nginx >> sbin folder and execute Nginx script.

./nginx stop
./nginx start

Another procedure would be using services:

systemctl stop nginx.service
systemctl start nginx.service

14. What is the main configuration file of Nginx?

nginx.conf is the main configuration file used in Nginx.

15. How to check the version of running Nginx Server?

There are multiple ways to find this but more accurately would be;

  • Go to Nginx instance and sbin folder
  • run the following command:
# ./nginx -v
nginx version: nginx/1.20.2

16. How to know if the Nginx server is running?

There are multiple ways to find this.

  1. Login to a web server and grep for “nginx” process
ps -ef |grep nginx
  1. Check if your apache IP:Port is accessible in the browser

Ex: http://127.0.0.1:80

  1. Check if configured IP and port are listening on the server with netstat
netstat -anlp |grep 80

17. How to install Nginx?

Refer to these articles for installation of Nginx

18. How to ensure the Nginx runs with a non-root/nobody user?

This is doable by adding the User & Group directive in nginx.conf file

User nginx
Group nginx

The above configuration example will ensure it starts with “nginx” user. You must ensure users exist on the server before configuring it.

19. How do I disable directory indexing?

You can use “autoindex off” inside the server tag in your configuration file.

Ex:

vi /etc/nginx/sites-available/default
##add this into server tag
autoindex off;

20. Which module is required to have redirection possible?

mod_rewrite is responsible for the redirection, and this must be uncommented in nginx.conf file.

load_module modules/ngx_http_rewrite_module.so;

Leave a Reply