Skip to main content
Below is a concise, structured recap of the key concepts from this lesson on NGINX intermediate configuration. Each item includes practical notes and short examples you can apply directly.

Server blocks (virtual hosts)

NGINX uses server blocks—defined with server { ... }—to host multiple sites on the same server. NGINX selects the appropriate server block using the server_name directive and the HTTP Host header.
  • Typical server block:
Use nginx -t after edits to validate configuration before reloading with systemctl reload nginx or nginx -s reload.

Redirecting HTTP to HTTPS

To force HTTPS, return a redirect from the HTTP server block. A permanent redirect (301) is commonly used for SEO and caching, but use 302 if you plan to revert later.
  • Permanent redirect example:
A 301 is cached by clients and search engines. Use 302 (temporary) during testing to avoid long-lived caches.

Rewrites and regex

Use location blocks and the rewrite directive to transform request URIs, implement clean URLs, or map legacy routes.
  • Clean URL rewrite example:
  • Prefer try_files for simple file-to-index fallbacks:

Upstreams and backend pools

Define backend pools with upstream { ... }. These pools let NGINX proxy requests to application servers and enable load balancing.
  • Upstream example:

Load balancing algorithms

NGINX supports several algorithms to distribute traffic. Choose based on session affinity, performance, and failure tolerance. Examples:
  • Weighted upstream:
  • IP hash:

Reverse proxy vs. load balancer

  • Reverse proxy: Forwards client requests to a backend application. Useful even with a single backend (e.g., proxying to a Flask app on port 5000 or a Node server).
  • Load balancer: Distributes traffic across multiple backends, providing scalability and failover. While a load balancer can point to a single server, you need multiple backends to realize load distribution and redundancy.
Practical tip: Combine roles—NGINX can act as both a reverse proxy and a load balancer, adding caching, SSL termination, and request rewriting in front of your application fleet.
A slide titled "Summary" with a blue gradient sidebar. It lists three points: a reverse proxy is a middleman to backend services, it’s not the same as a load balancer, and Nginx can be used as a cache server to boost performance.

Caching

NGINX caching reduces backend load and speeds up responses by storing upstream responses locally using proxy_cache.
  • Basic cache setup:
Best practices:
  • Honor or control Cache-Control and Expires headers appropriately.
  • Use cache-busting or cache purging strategies for dynamic content.
  • Monitor X-Proxy-Cache and cache directory size to avoid stale content and disk overuse.
And that wraps it up for this lesson.

Watch Video