// The web server built for speed.
NGINX IS THE CHOICE FOR PERFORMANCE.
Originally created to solve the C10K problem (handling 10,000+ concurrent connections), NGINX powers over 400 million websites worldwide. It's the secret behind Netflix, Instagram, and WordPress.com.
WHY NGINX?
NGINX uses an asynchronous, event-driven architecture that handles massive traffic with minimal memory. It's faster than Apache for static content and excels as a reverse proxy and load balancer.
TAKE CONTROL OF PERFORMANCE.
Learn to configure NGINX as a web server, reverse proxy, or load balancer. Master caching, SSL/TLS, and optimization techniques to build lightning-fast deployments.
12 lessons. Complete NGINX control.
High-performance web server and reverse proxy
BeginnerSet up on Debian/Ubuntu and RHEL/CentOS
BeginnerMaster nginx.conf structure
BeginnerHost multiple websites on one server
IntermediateSecure sites with Let's Encrypt certificates
IntermediateForward requests to backend applications
IntermediateDistribute traffic across multiple servers
IntermediateImprove performance with content caching
IntermediateHarden NGINX against attacks
AdvancedTune worker processes and buffers
AdvancedConfigure PHP-FPM for dynamic content
IntermediateFix configuration errors and optimize
AdvancedNGINX (pronounced "engine-x") was created by Igor Sysoev in 2004 to solve the C10K problem. Its event-driven, asynchronous architecture makes it incredibly efficient at handling concurrent connections.
Unlike Apache's process-per-request model, NGINX uses a single worker process that can handle thousands of connections simultaneously. This makes it ideal for high-traffic sites and real-time applications.
NGINX is dual-licensed: free open-source version and commercial NGINX Plus with additional features. The open-source version is perfect for most use cases.
When performance matters, the web runs on NGINX. Now you can too.
NGINX (engine-x) is a high-performance web server, reverse proxy, and load balancer. Created in 2004 by Igor Sysoev, it was designed to solve the C10K problem—handling 10,000+ concurrent connections.
NGINX offers several advantages:
| Architecture | Event-driven, async | Process/thread per request |
| Static Content | Faster | Slower |
| Dynamic Content | Via external handlers | Native modules |
| Configuration | .conf files | .htaccess + conf |
| OS Support | All Unix-like | All |
1. NGINX was created to solve the _____ problem.
Hint: 10,000 connections
2. NGINX uses an _____ architecture.
Hint: Async
3. NGINX serves _____ content faster than Apache.
Hint: HTML, images, etc.
4. The default document root is _____.
Hint: Under /var/www
5. NGINX is pronounced _____.
Hint: Not
6. The main config file is _____.
Hint: In /etc/nginx/
7. To check NGINX version, use _____ -v.
Hint: The binary name
8. Sites are configured in _____ directory.
Hint: Available sites
Installing NGINX on Debian-based systems is straightforward using apt:
On RHEL-based systems, add the EPEL repository first:
After installation, verify NGINX is serving pages:
Or open http://localhost in your browser. You should see the default NGINX welcome page.
1. On Ubuntu, NGINX is installed with the _____ command.
Hint: Uses apt package manager
2. On CentOS, you need _____ first.
Hint: Extra Packages
3. To start NGINX on systemd, use _____.
Hint: systemctl
4. To enable NGINX on boot, use _____ enable.
Hint: systemctl enable
5. To test config syntax, use _____.
Hint: Test configuration
6. After config changes, you should _____ NGINX.
Hint: systemctl reload
7. You can test NGINX with _____ localhost.
Hint: Command-line HTTP client
8. The configuration test shows _____.
Hint: Configuration is valid
NGINX uses a hierarchical configuration system with directives organized in blocks. Understanding this structure is key to effective server administration.
The primary configuration file is /etc/nginx/nginx.conf:
Specifies which user NGINX runs as:
Number of worker processes (auto = number of CPU cores):
Maximum connections per worker:
IP and port to listen on:
Domain name(s) for the server block:
Document root directory:
The location block matches URI patterns:
NGINX uses include directives to modularize configuration:
1. The main NGINX configuration file is _____.
Hint: In /etc/nginx/
2. The _____ directive specifies the web root directory.
Hint: Where files are served from
3. worker_processes _____ uses all CPU cores.
Hint: Automatic detection
4. The maximum connections per worker is _____.
Hint: In events block
5. The location block matches _____.
Hint: URL paths
6. The _____ directive specifies domain names.
Hint: Domain names
7. To include other config files, use _____.
Hint: Include directive
8. NGINX runs as _____ by default on Ubuntu.
Hint: Unprivileged user
Server blocks in NGINX (equivalent to Apache's Virtual Hosts) allow you to serve multiple websites from a single server. Each block defines configuration for a specific domain.
Create a configuration file in /etc/nginx/sites-available/:
The default site serves requests that don't match any server_name:
You can have multiple server blocks:
Handle all requests to unknown domains:
1. NGINX server blocks are equivalent to Apache
Hint: Multiple sites
2. To enable a site, create a _____ to sites-enabled.
Hint: Symbolic link
3. The server_name directive defines _____ names.
Hint: Domain names
4. Server block configs are in _____ directory.
Hint: Available sites
5. The default_server option makes a site _____.
Hint: Default for unmatched
6. server_name _____ matches any domain.
Hint: Underscore
7. Always test config with _____ before reload.
Hint: Test configuration
8. The default site serves requests matching no _____.
Hint: Domain name
SSL/TLS encrypts communication between the server and clients, protecting sensitive data from interception. It's essential for security, SEO, and user trust.
Redirect all HTTP traffic to HTTPS:
1. _____ encrypts communication between server and client.
Hint: HTTPS
2. Let
Hint: DV certificates
3. The ssl_certificate directive specifies the _____.
Hint: Public key file
4. The ssl_certificate_key directive specifies the _____.
Hint: Secret key file
5. To redirect HTTP to HTTPS, use _____ directive.
Hint: 301 redirect
6. Self-signed certificates are for _____ only.
Hint: Not production
7. certbot is used to obtain _____ certificates.
Hint: From Let
8. HTTP/2 requires _____.
Hint: Must be HTTPS
A reverse proxy sits between clients and backend servers. It forwards client requests to appropriate backends and returns responses. NGINX excels at this role.
Important headers for backend servers:
For PHP-FPM and other services:
1. A reverse _____ sits between clients and backend servers.
Hint: Forwards requests
2. The proxy_pass directive specifies the _____ server.
Hint: Target server
3. X-Real-IP header contains the _____ IP address.
Hint: Original client
4. For WebSocket, set Connection to _____.
Hint: Upgrade header
5. proxy_pass can use a _____ socket.
Hint: PHP-FPM
6. X-Forwarded-For contains the _____ IP.
Hint: Client IP through proxies
7. To hide backend servers, use a _____ proxy.
Hint: Reverse proxy
8. The Host header should be set to _____.
Hint: Variable
Load balancing distributes incoming traffic across multiple backend servers. NGINX can balance load using various algorithms and health checks.
Sticky sessions - same client goes to same server:
Mark servers as down if they fail:
1. Load _____ distributes traffic across servers.
Hint: Distribution
2. _____ method sends requests in order.
Hint: Default method
3. _____ method uses fewest active connections.
Hint: Load balancing
4. ip_hash provides _____ sessions.
Hint: Same client to same server
5. The backup flag marks a server as _____.
Hint: Fallback
6. max_fails determines server _____ threshold.
Hint: Failure count
7. Upstream blocks define _____ servers.
Hint: Target servers
8. Weight=5 gives a server _____ times more requests.
Hint: Five times
NGINX can cache responses from backend servers, reducing load and improving response times dramatically.
Install ngx_cache_purge module for on-demand purging:
Set headers for client-side caching:
1. Proxy cache stores responses from _____ servers.
Hint: Proxy target
2. The keys_zone directive defines _____ memory.
Hint: In memory
3. proxy_cache_bypass skips cache based on _____.
Hint: HTTP headers
4. FastCGI cache is for _____ content.
Hint: PHP, etc.
5. The expires directive sets _____ caching.
Hint: Client-side
6. X-FastCGI-Cache shows cache _____.
Hint: HIT, MISS, etc.
7. Cache size is limited by _____ parameter.
Hint: Maximum size
8. Inactive items are purged after _____ time.
Hint: inactive parameter
Securing NGINX is critical. A misconfigured web server can expose sensitive data or become a vector for attacks.
Don't reveal server version to attackers:
Block access to config files:
Prevent DoS attacks with large requests:
Limit requests from a single IP:
Add headers to protect against common attacks:
NGINX should run as www-data, not root (already configured by default):
1. server_tokens _____ hides NGINX version.
Hint: Hide version
2. autoindex _____ disables directory listing.
Hint: Disable
3. Security headers are added with _____ header.
Hint: Header directive
4. X-Frame-Options prevents _____ attacks.
Hint: iframe embedding
5. client_max_body_size prevents _____ attacks.
Hint: Denial of Service
6. NGINX should run as _____, not root.
Hint: Unprivileged user
7. rate limiting uses _____ zone.
Hint: Rate limit
8. deny all blocks _____ addresses.
Hint: IP addresses
Optimizing NGINX improves page load times, reduces server load, and provides better user experience.
Use epoll for Linux:
Reduce overhead with persistent connections:
Optimize proxy buffering:
Cache file metadata:
Use kernel sendfile for faster file serving:
1. worker_processes _____ auto-detects CPU cores.
Hint: Automatic
2. Use _____ for event processing on Linux.
Hint: Linux event model
3. Gzip _____ determines compression level.
Hint: 1-9
4. Keep-alive reduces _____ overhead.
Hint: TCP overhead
5. _____ caching stores file metadata.
Hint: File cache
6. Sendfile uses _____ for file transfer.
Hint: OS kernel
7. tcp_nopush optimizes _____ packets.
Hint: Network packets
8. proxy_buffers should be sized based on _____ content.
Hint: Response size
NGINX doesn't have native PHP support like Apache. Instead, it passes PHP requests to PHP-FPM (FastCGI Process Manager).
Ubuntu includes a fastcgi-php.conf snippet:
Edit /etc/php/8.1/fpm/pool.d/www.conf:
1. NGINX passes PHP to _____.
Hint: FastCGI Process Manager
2. The fastcgi_pass directive specifies the _____.
Hint: Unix socket
3. PHP-FPM uses the _____ protocol.
Hint: Interface
4. SCRIPT_FILENAME contains the _____ path.
Hint: PHP file path
5. Ubuntu has a _____ for PHP config.
Hint: fastcgi-php.conf
6. PM in PHP-FPM stands for _____ Manager.
Hint: Process Manager
7. To test PHP, create a _____ file.
Hint: phpinfo()
8. PHP-FPM pools are configured in _____ directory.
Hint: Pool configs
Understanding common issues and how to debug them is essential for NGINX administration.
Enable debug logging:
1. 403 Forbidden is usually _____ issues.
Hint: File/directory
2. 502 Bad Gateway usually means _____ is down.
Hint: Backend service
3. To test config, use _____ -t.
Hint: Test command
4. Debug logging uses _____ level.
Hint: Most verbose
5. reload is _____ (interrupts/no interrupts).
Hint: No interrupts
6. netstat shows _____ usage.
Hint: Network ports
7. PHP-FPM 502 is often socket _____ issues.
Hint: Ownership
8. nginx _____ shows full config.
Hint: Test and view