Nginx Interview Questions Hindi mein

Nginx कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

NGINX Foundations

1. How does an NGINX worker process handle many connections at once?

  1. With a single-threaded, event-driven, non-blocking loop
  2. By creating a new thread per connection
  3. By forking a process per request
  4. By queuing connections until one finishes
जवाब देखें

जवाब: With a single-threaded, event-driven, non-blocking loop

Workers react to I/O events for thousands of connections without a thread per connection.

पाठ: What NGINX Does and How It Works

2. What does `nginx -s reload` do?

  1. Stops NGINX immediately and starts it again
  2. Only checks syntax
  3. Clears all logs
  4. Starts workers with the new configuration while old workers finish in-flight requests
जवाब देखें

जवाब: Starts workers with the new configuration while old workers finish in-flight requests

A reload is graceful, avoiding dropped connections.

पाठ: Installing, Files and Controlling NGINX

3. Which context contains location blocks?

  1. events
  2. stream
  3. server (inside http)
  4. main only
जवाब देखें

जवाब: server (inside http)

Location blocks live inside server blocks within the http context.

पाठ: Configuration Structure, Contexts and Inheritance

Server Blocks, Locations and Static Files

4. No server_name matches a request's Host header. Which server block handles it?

  1. NGINX returns 500
  2. The last server block in the file
  3. The default server for that listen address and port
  4. A random server
जवाब देखें

जवाब: The default server for that listen address and port

The default_server (or the first defined) for the matching listen socket handles unmatched hosts.

पाठ: Server Blocks and Request Routing by Host

5. A request for /static/logo.png matches `location /static/` and `location ~* \.png$`. Neither uses ^~. Which wins?

  1. location /static/, because it is longer
  2. location ~* \.png$, because regex locations are checked after the prefix and the first matching regex wins
  3. Whichever appears first in the file, always
  4. Neither; NGINX returns 404
जवाब देखें

जवाब: location ~* \.png$, because regex locations are checked after the prefix and the first matching regex wins

A matching regex overrides the longest prefix unless that prefix is marked ^~.

पाठ: Location Matching Rules

6. With `location /media/ { alias /data/uploads/; }`, which file serves /media/cat.png?

  1. /data/uploads/cat.png
  2. /data/uploads/media/cat.png
  3. /media/cat.png
  4. /var/www/media/cat.png
जवाब देखें

जवाब: /data/uploads/cat.png

alias replaces the matched prefix, whereas root would append the whole URI.

पाठ: Serving Static Files and Single-Page Apps

Reverse Proxying

7. Why set `proxy_set_header X-Forwarded-Proto $scheme`?

  1. So the application knows whether the client used HTTP or HTTPS
  2. To compress responses
  3. To enable HTTP/2
  4. To cache responses
जवाब देखें

जवाब: So the application knows whether the client used HTTP or HTTPS

The app sees only NGINX's connection, so the original scheme must be forwarded explicitly.

पाठ: proxy_pass and Forwarded Headers

8. With `location /api/ { proxy_pass http://backend/; }`, what URI does the backend receive for /api/users?

  1. /api/users
  2. /backend/users
  3. /
  4. /users
जवाब देखें

जवाब: /users

Because proxy_pass includes a URI (/), the matched /api/ prefix is replaced by /.

पाठ: URIs, Timeouts, Buffering and WebSockets

Load Balancing

10. Requests to an API vary from 5 ms to several seconds. Which method usually balances better than plain round robin?

  1. ip_hash
  2. backup
  3. least_conn
  4. down
जवाब देखें

जवाब: least_conn

least_conn accounts for in-flight work, avoiding piling requests on a busy server.

पाठ: Upstream Groups and Balancing Methods

11. By default, will NGINX retry a POST request on another upstream after it was already sent and the upstream timed out?

  1. Yes, always
  2. No, not unless non_idempotent is added to proxy_next_upstream
  3. Only on Sundays
  4. Only with ip_hash
जवाब देखें

जवाब: No, not unless non_idempotent is added to proxy_next_upstream

NGINX avoids retrying non-idempotent requests to prevent duplicate side effects.

पाठ: Failures, Retries and Keepalive to Upstreams

12. Which NGINX context is used to load balance a PostgreSQL TCP service?

  1. stream
  2. http
  3. location
  4. events
जवाब देखें

जवाब: stream

The stream module handles raw TCP and UDP proxying, outside the http context.

पाठ: TCP and UDP Load Balancing with the stream Module

HTTPS, HTTP/2 and HTTP/3

13. Which TLS protocol versions should a modern NGINX configuration allow?

  1. TLSv1.2 and TLSv1.3
  2. SSLv3 and TLSv1.0
  3. TLSv1.0 through TLSv1.3
  4. Only TLSv1.1
जवाब देखें

जवाब: TLSv1.2 and TLSv1.3

TLS 1.0 and 1.1 are deprecated; 1.2 and 1.3 are the secure, supported versions.

पाठ: Configuring TLS

14. What extra network change is usually required to serve HTTP/3?

  1. Opening TCP port 80
  2. Disabling TLS
  3. Enabling SSLv3
  4. Allowing UDP port 443 through firewalls
जवाब देखें

जवाब: Allowing UDP port 443 through firewalls

HTTP/3 runs over QUIC on UDP, so UDP 443 must be allowed.

पाठ: HTTP/2 and HTTP/3

15. Which is the simplest correct way to redirect all HTTP traffic to HTTPS while keeping the path?

  1. rewrite ^ https://$host;
  2. proxy_pass https://$host;
  3. return 301 https://$host$request_uri;
  4. try_files https://$host;
जवाब देखें

जवाब: return 301 https://$host$request_uri;

return with $request_uri preserves the path and query string without regex processing.

पाठ: Redirects, HSTS and Canonical Hosts

Caching, Compression and Performance

16. Which directive lets NGINX keep serving cached content when the upstream returns 502 errors?

  1. proxy_cache_lock
  2. proxy_buffering
  3. proxy_cache_use_stale
  4. proxy_set_header
जवाब देखें

जवाब: proxy_cache_use_stale

proxy_cache_use_stale specifies conditions under which stale cached content may be served.

पाठ: Proxy Caching

17. Which content type should normally NOT be gzip-compressed by NGINX?

  1. application/json
  2. image/jpeg
  3. text/css
  4. application/javascript
जवाब देखें

जवाब: image/jpeg

JPEG is already compressed; gzipping it wastes CPU for no benefit.

पाठ: Compression

18. Why add `keepalive` to an upstream block?

  1. To reuse connections to backend servers instead of opening a new one per request
  2. To cache responses
  3. To enable HTTP/3
  4. To compress responses
जवाब देखें

जवाब: To reuse connections to backend servers instead of opening a new one per request

Upstream keepalive avoids repeated TCP (and TLS) handshakes to backends.

पाठ: Performance Tuning Basics

Security, Limits and Observability

19. What does `nodelay` change in `limit_req zone=api burst=40 nodelay;`?

  1. Burst requests are served immediately instead of being delayed to match the rate
  2. It disables the limit
  3. It returns 429 for every request
  4. It only applies to POST requests
जवाब देखें

जवाब: Burst requests are served immediately instead of being delayed to match the rate

Without nodelay, burst requests are queued and released at the configured rate.

पाठ: Rate Limiting, Connection Limits and Request Size

20. Why add the `always` parameter to add_header for security headers?

  1. To make the header apply to all servers
  2. To make the header case-insensitive
  3. To disable caching
  4. So the header is also added to error responses such as 404 and 500
जवाब देखें

जवाब: So the header is also added to error responses such as 404 and 500

Without always, add_header applies only to successful and redirect responses.

पाठ: Access Control, Authentication and Security Headers

21. Which variable shows how long the backend took to respond?

  1. $request_time
  2. $remote_addr
  3. $upstream_response_time
  4. $status
जवाब देखें

जवाब: $upstream_response_time

$upstream_response_time measures the backend; $request_time covers the whole request.

पाठ: Logging, Metrics and Troubleshooting

NGINX in Practice and Revision

22. Why should new Kubernetes clusters avoid adopting the community ingress-nginx controller?

  1. It cannot route HTTP
  2. It only supports UDP
  3. The Kubernetes project announced its retirement, so it no longer receives maintenance
  4. It requires NGINX Plus
जवाब देखें

जवाब: The Kubernetes project announced its retirement, so it no longer receives maintenance

With the project retired, maintained controllers or Gateway API implementations are safer choices.

पाठ: NGINX in Containers and Kubernetes

23. What is the generally recommended alternative to complex `if` logic inside locations?

  1. Nested if statements
  2. map blocks and try_files
  3. Lua scripts in every location
  4. Disabling the rewrite module
जवाब देखें

जवाब: map blocks and try_files

map computes variables cleanly and try_files handles file fallbacks without if.

पाठ: Common Mistakes

24. In the case study, why are requests with an Authorization header excluded from the micro-cache?

  1. Authenticated responses may be user-specific, so caching them could leak data between users
  2. Authorization headers are too large to cache
  3. NGINX cannot read headers
  4. Caching would disable rate limiting
जवाब देखें

जवाब: Authenticated responses may be user-specific, so caching them could leak data between users

User-specific responses must not be stored in a shared cache keyed only by URL.

पाठ: Case Study: A Complete Production Front End

25. Which location type is checked first and wins immediately when it matches?

  1. A regex location with ~*
  2. A prefix location with ^~
  3. The longest plain prefix
  4. An exact match location with =
जवाब देखें

जवाब: An exact match location with =

Exact matches (=) are selected immediately, before any prefix or regex evaluation.

पाठ: Revision and Interview Questions

← कोर्स पर वापस जाएँ