Top 18 Nginx Interview Questions & Answers

1) Explain what is Nginx?

Nginx is a web server and a reverse proxy server for HTTP, HTTPS, SMTP, POP3 and IMAP protocols.

2) Mention some special features of Nginx?

Special features of the Nginx server includes

  • Reverse proxy/ L7 Load Balancer
  • Embedded Perl interpreter
  • On the fly binary upgrade
  • Useful for re-writing URLs and awesome PCRE support

3) Mention what is the difference between Nginx and Apache?

                            Nginx                                  Apache
  • Nginx is an event based web server
  • All request are handled by a single thread.
  • Nginx avoids child processes idea.
  • Nginx resembles speed
  • Nginx is better when it comes to memory consumption and connection
  • Nginx is better when you want load-balancing
  • For PHP, Nginx might be preferable as it supports PHP internally
  • Nginx do not support O.S like IBMi and OpenVMS.
  • Nginx comes only with core features
  • Nginx performance and scalability do not depend on hardware
  •  Apache is a process based server
  • Single thread handles a single request.
  • Apache is based on child processes
  • Apache resemble power
  • Apache is not up-to the mark when it comes to memory consumption and connection
  • Apache will refuse new connections when traffic reaches the limit of processes
  • Apache support’s PHP, Python, Perl and other languages using plugins. It is useful when application is based on Python or Ruby
  • Apache support much wider range of O.S
  • Apache provides lot more functionality than Nginx
  • Apache is dependent on hardware components like CPU and memory

4) 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 read 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.

5) In Nginx how you can prevent processing requests with undefined server names?

A server that just drops the requests can be defined as

 

Server {

listen                80;

server_name  “ “ ;

return              444;

}


Here the server name is kept as an empty string which will match request without the “Host” header field, and a special Nginx’s non-standard code 444 is returned that terminates the connection.

Nginx-logo

6) What is the advantage of using a “reverse proxy server”?

The reverse proxy server can hide the presence and characteristics of the origin server. It acts as an intermediate between internet cloud and web server. It is good for security reason especially when you are using web hosting services.

7) Mention what is the best usage of Nginx server?

The best usage of Nginx server is to deploy dynamic HTTP content on a network with using SCGI, WSGI application servers, FastCGI handlers for scripts.  It can also serve as a load balancer.


8) Mention what is the Master and Worker Processes in Nginx Server?

  • Master processes: It reads as well as evaluates configuration and maintains worker processes.
  • Worker processes: It actually does the processing of the requests.

9) Explain how you can start Nginx through a different port other than 80?

To start Nginx through a different port, you have to go to /etc/Nginx/sites-enabled/ and if this is the default file, then you have to open file called “default.” Edit the file and put the port you want

Like server { listen 81; }

10) Explain is it possible to replace Nginx errors like 502 error with 503?

  • 502= Bad gateway
  • 503= Server overloaded

Yes, it is possible but you to ensure that fastcgi_intercept_errors is set to ON, and use the error page directive.

 

Location / {

fastcgi_pass 127.0.01:9001;

fastcgi_intercept_errors on;

error_page 502 =503/error_page.html;

#…

}

11) In Nginx, explain how you can keep double slashes in URLs?

To keep double slashes in URLs you have to use merge_slashes_off;

Syntax: merge_slashes [on/off]

Default: merge_slashes on

Context: http, server

12) Explain what is ngx_http_upstream_module is used for?

The ngx_http_upstream_module is used to define groups of servers that can reference by the fastcgi pass, proxy pass, uwsgi pass, memcached pass and scgi pass directives.

13) Explain what is C10K problem?

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

14) Mention what is the use of stub_status and sub_filter directives?

  • Stub_status directive: This directive is used to know the current status of Nginx like current active connection, total connection accepted and handled current number of read/write/wait connection
  • Sub_filter directive: It is used to search and replace the content in response, and quick fix for stale data

15) 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 “gzip” encoding method.

16) Explain how you can get the current time in Nginx?

To get the current time in Nginx, you have to use variables from SSI module, $date_gmt and $date_local.

  • Proxy_set_header THE-TIME $date_gmt;

17) Explain what is the purpose of –s with Nginx Server?

To run the executable file of Nginx –s parameter is used.

18) 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.


FacebookTwitter
4 replies

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. venu gopal Choudhary says:

    I have noticed a wrong statement in your article.

    8) Mention what is the Master and Worker Processes in Nginx Server?

    Please update it.
    Master process maintains configuration and workers does the process.

    Reply
    • Guru99 says:

      There is some misunderstanding, the answer implies the same.

      Reply
    • bibhu bal says:

      correct please update it. Master process maintains config and read as well as controlling and maintaining worker where as worker does the process.

      Reply
    • Guru99 says:

      Thanks! Error Fixed

      Reply