Skip to content
Guest
Cloud & DevOps · Course Syllabus Show lessons
Nginx & HTTPS · 8 min read · Intermediate

Nginx Reverse Proxy, Gzip & Asset Caching

Write clean Nginx server blocks that serve static sites, proxy `/api/`, compress text assets, and cache hashed bundles.

What you'll learn

  • Forward real client IPs via `X-Forwarded-For` and `X-Real-IP`
  • Cache content-hashed JS/CSS bundles for 1 year (`immutable`)
  • Keep HTML and `sw.js` uncached or `no-cache` so deploys show up immediately

Overview

Write clean Nginx server blocks that serve static sites, proxy /api/, compress text assets, and cache hashed bundles.

Code Example

location /api/ {
    proxy_pass http://127.0.0.1:8787;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /_astro/ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

Key Takeaways

  • Forward real client IPs via X-Forwarded-For and X-Real-IP
  • Cache content-hashed JS/CSS bundles for 1 year (immutable)
  • Keep HTML and sw.js uncached or no-cache so deploys show up immediately

Quick Check

Check Your Understanding

Score: 0 / 1

1. Which command verifies Nginx config syntax before applying changes?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind