Skip to content
Tutorials Center
My learning

Topics

Nginx and Apache Tutorial

Learn Nginx and Apache step by step: 30 lessons in 10 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

First Steps

  1. 1 What a Web Server Does Learn what a web server does: the HTTP request/response cycle, ports and sockets, static vs dynamic content and why Nginx or Apache sits in front of your app.
  2. 2 Installing and Finding Your Way Around Install Nginx and Apache on Debian, Ubuntu and RHEL, learn where config, logs and web roots live, test config safely and reload with systemctl or Docker.
  3. 3 Nginx vs Apache: Architecture and Choosing Compare Nginx and Apache: event-driven workers vs prefork, worker and event MPMs, memory per connection, modules, .htaccess trade-offs and when to use both.

Nginx Configuration

  1. 4 Nginx Configuration Syntax Learn the Nginx config language: simple and block directives, the main, events, http, server and location contexts, inheritance, include, variables and add_header traps.
  2. 5 Server Blocks and Choosing a Server Learn Nginx server blocks: listen and server_name, exact, wildcard and regex names, default_server, the order Nginx uses to pick a server and a catch-all that drops unknown hosts.
  3. 6 Location Blocks and Matching Order Master Nginx location blocks: exact, prefix, ^~ and regex modifiers, the longest-prefix rule, evaluation order, named and nested locations, root vs alias and try_files.

Apache Configuration

  1. 7 Apache httpd Configuration Learn how Apache httpd is configured: apache2.conf and httpd.conf, directives, Directory, Files and Location containers, merge order, modules and MPMs.
  2. 8 Apache Virtual Hosts Host many sites on one Apache server: name-based and IP-based virtual hosts, ServerName and ServerAlias, the first-vhost default, per-site logs and Listen.
  3. 9 .htaccess, Directory Rules and AllowOverride Understand .htaccess files and per-directory rules in Apache: AllowOverride, Require access control, Options, the performance cost, and moving rules into the main config.

Serving Content

  1. 10 Redirects and Rewrites Learn redirects and rewrites in nginx and Apache: return vs rewrite, RewriteRule and RewriteCond, flags, canonical host, HTTP to HTTPS and redirect loops.
  2. 11 Static Files, Caching and MIME Types Serve static files fast with nginx and Apache: root and index, MIME types, ETag and Last-Modified, Cache-Control, immutable assets, pre-compression and error pages.
  3. 12 PHP, FastCGI and Application Servers Connect nginx and Apache to PHP-FPM with FastCGI, set up a front controller with try_files or mod_rewrite, compare mod_php and proxy_fcgi, and reach uwsgi and Node.

Proxying and Load Balancing

  1. 13 Reverse Proxy Basics Learn how a reverse proxy works: nginx proxy_pass and its trailing-slash rule, Host and X-Forwarded headers, real client IP, Apache ProxyPass, timeouts and buffering.
  2. 14 Load Balancing and Health Checks Spread traffic over several backends with nginx upstream blocks and Apache mod_proxy_balancer: round-robin, least_conn, ip_hash, weights, backups and failure handling.
  3. 15 WebSockets, Streaming and Long Requests Make long-lived connections work through a proxy: WebSocket Upgrade headers, proxy_http_version, read timeouts, SSE without buffering and client_max_body_size.
  4. 16 Nginx in Front of Apache Put nginx in front of Apache: who does what, passing the real client IP with mod_remoteip, avoiding double compression, port layout and when the stack is not worth it.

HTTPS and Modern HTTP

  1. 17 HTTPS, TLS and Let's Encrypt Understand certificates, chains and the TLS handshake, then enable HTTPS in nginx and Apache with certbot, automatic renewal, HTTP-to-HTTPS redirects and SNI.
  2. 18 HTTP/2, HTTP/3, gzip and Brotli Enable HTTP/2 and HTTP/3 in nginx and Apache, understand multiplexing and what it makes obsolete, and tune gzip and Brotli compression: levels, types and what to skip.

Security and Hardening

  1. 19 Access Control and Rate Limiting Restrict who can reach a URL with allow/deny, Require ip and Basic auth, then slow abusive clients with limit_req, limit_conn and fail2ban.
  2. 20 Hardening and Security Headers Harden nginx and Apache: hide version tokens, set HSTS, CSP and nosniff headers, block dotfiles and backups, run workers unprivileged and cap requests.

Operations and Performance

  1. 21 Logs and Troubleshooting Read nginx and Apache access and error logs, customize log formats, diagnose 403, 404, 502, 503 and 504, and debug with nginx -T, httpd -S and curl.
  2. 22 Performance Tuning Tune nginx and Apache for speed: workers and connections, keep-alive, open file cache, buffers, Apache event MPM limits, proxy and FastCGI caching.
  3. 23 Reloads, Zero-Downtime Deploys and Containers Reload nginx and Apache without dropping requests, see how old workers drain, switch backends blue-green, run both servers in Docker and test configs in CI.

Real-World Projects

  1. 24 Project: Host a Static Site with HTTPS and Caching Build a complete static-site setup twice, on nginx and on Apache: HTTPS, www redirect, custom 404, cache headers, compression and security headers.
  2. 25 Project: A PHP Application with Clean URLs Build a production-style setup for a Laravel-style PHP app: front controller, PHP-FPM, clean URLs, protected storage and dotfiles, upload limits, on Nginx and Apache.
  3. 26 Project: Reverse Proxy for Several Apps Put one Nginx or Apache entry point in front of a Node API, a Python app and a WebSocket service: path and subdomain routing, rewriting, timeouts and headers.
  4. 27 Project: A Secure Load-Balanced Production Setup Assemble a production edge: TLS termination, an upstream pool with passive health checks, rate limiting, caching, security headers, useful logs and a safe reload routine.

Practice and Review

  1. 28 Practice: Configuration Exercises with Solutions Twelve graded Nginx and Apache configuration exercises with solutions: locations, redirect loops, vhost choice, proxy_pass slashes, alias traps, limits and more.
  2. 29 Interview Questions Prepare for Nginx and Apache interviews: concepts, nginx vs Apache, location matching, reverse proxying, TLS and troubleshooting scenarios with concise answers.
  3. 30 Nginx and Apache Cheat Sheet A side-by-side Nginx and Apache cheat sheet: matching directives, everyday commands, status code causes and copy-ready snippets for redirects, proxy, cache and TLS.