Top Nginx Interview Questions: Master High‑Concurrency Web Server Concepts
This article compiles essential Nginx interview questions covering its definition, key features, differences from Apache, request handling mechanisms, master‑worker architecture, proxy types, module usage, and common configuration directives, providing a comprehensive guide for backend engineers preparing for technical interviews.
Nginx's concurrency capability is among the best of web servers, making it popular with enterprises such as Tencent, Taobao, Baidu, JD.com, Sina, and NetEase. It is a must‑know skill for web‑server operators, and the following are common Nginx interview questions for reference.
1. What is Nginx?
Nginx (Engine X) is a free, open‑source, high‑performance HTTP server and reverse proxy server; it also serves as an IMAP, POP3, and SMTP proxy. It is known for high performance, stability, rich features, simple configuration, and low resource consumption.
In other words, Nginx can host websites (similar to Tomcat), handle HTTP services, and act as a reverse proxy, load balancer, and HTTP cache.
Nginx solves the C10K problem (handling 10,000 concurrent connections). Unlike traditional servers that use threads, Nginx employs an event‑driven, asynchronous architecture.
2. List some Nginx features
Cross‑platform: runs on most Unix‑like systems and has a Windows port.
Simple configuration: easy to learn.
Non‑blocking, high‑concurrency connections: supports up to 50,000 concurrent connections in official tests, and 20,000‑30,000 in production, thanks to the epoll event model.
No long connections required between Nginx proxy and backend web servers.
Asynchronous request handling reduces backend server load.
While sending responses, Nginx streams data from the backend to the client simultaneously.
Low network dependency; load balancing works as long as the host is reachable.
Built‑in server health checks based on status codes and timeouts.
Low memory usage, low cost compared to hardware load balancers, bandwidth savings, and high stability.
3. Differences between Nginx and Apache
4. How does Nginx process HTTP requests?
Nginx combines a multi‑process mechanism with an asynchronous, non‑blocking model to handle many concurrent requests.
1. Multi‑process mechanism
When the server receives a client connection, the master process forks a worker process to handle the interaction until the connection closes.
Using separate processes avoids locking, reduces complexity, and isolates failures; if a worker crashes, the master quickly spawns a new one.
The downside is the overhead of creating processes and memory copying.
2. Asynchronous non‑blocking mechanism
Each worker uses asynchronous non‑blocking I/O to handle multiple client requests. If an I/O operation cannot complete immediately, the worker proceeds to other requests (non‑blocking). The client does not wait for a response (asynchronous). When I/O completes, the worker is notified and resumes processing.
5. How to block requests with an undefined server name?
Define a server block with an empty server_name and return the non‑standard code 444 to terminate the connection.
6. Advantages of using a reverse proxy server
A reverse proxy hides the origin server's existence and characteristics, acting as an intermediary between the internet and web servers, which improves security, especially for hosted services.
7. Best use cases for Nginx
Deploy dynamic HTTP content, use SCGI/WSGI/FastCGI for script processing, and serve as a load balancer.
8. What are the Master and Worker processes?
The master process starts, receives and handles external signals.
The master forks worker processes; each worker runs a loop to receive and process events.
Typically, the number of workers equals the number of CPU cores to avoid excessive process creation and context switching. Nginx also supports CPU affinity to bind workers to specific cores.
Each request is handled by a single worker. Workers inherit a listening socket from the master, then compete for an accept mutex to ensure only one worker accepts a new connection. After accepting, the worker reads, parses, processes the request, sends the response, and closes the connection.
9. Forward proxy vs. reverse proxy
A forward proxy operates on the client side, forwarding client requests to external servers (e.g., GoAgent for bypassing firewalls).
A reverse proxy operates on the server side, receiving client requests and forwarding them to backend servers, then returning the responses to clients. Nginx is a reverse proxy.
10. Can Nginx replace errors with 502 or 503?
502 = Bad Gateway, 503 = Server Overload. It is possible by enabling fastcgi_intercept_errors and configuring error_page directives.
11. How to preserve double slashes in URLs?
Set merge_slashes off in the configuration.
Syntax: merge_slashes [on/off] Default: merge_slashes on Context: http, server
12. What does the ngx_http_upstream_module do?
It defines server groups that can be referenced by fastcgi, proxy, uwsgi, memcached, and scgi directives.
13. What is the C10K problem?
The C10K problem refers to the difficulty of handling 10,000 simultaneous network sockets.
14. Purpose of stub_status and sub_filter directives
stub_status provides current Nginx status, including active connections and total accepted, handled, and waiting connections.
sub_filter searches and replaces content in responses, useful for quickly fixing outdated data.
15. Does Nginx support compressing requests to upstream?
Yes, the gunzip module can decompress responses for clients or upstream servers that do not support gzip encoding.
16. How to obtain the current time in Nginx?
Use the SSI module with the $date_gmt variable, e.g.,
proxy_set_header THE-TIME $date_gmt;17. What is the purpose of the -s option?
It runs the Nginx executable with the specified signal parameter.
18. How to add a module to Nginx?
Modules must be selected at compile time; Nginx does not support dynamic module loading at runtime.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
