·

Nginx Reverse Proxy Explained (With Real Examples for PHP and Next.js)

Understand reverse proxy with simple Nginx examples: routing traffic to PHP-FPM and Next.js safely.

A reverse proxy sits in front of your app and decides where requests should go. It can route traffic, add headers, cache responses, and terminate SSL.

Example: route /api to PHP, / to Next.js

server {
  listen 80;

  location /api/ {
    proxy_pass http://php-backend;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location / {
    proxy_pass http://nextjs-frontend;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Why this matters

  • Clean separation of services
  • Better security via header control
  • Faster delivery via caching/CDN integration

Once you understand routing, you can add caching rules and rate limiting for sensitive endpoints.

Filed under:

Need help with your website?

Start with a Website Health Check for $49 and get a clear, written report of what your site needs.

Need help with your website? Get a Website Health Check + QA Report for $49 — a clear, written review of your site’s performance, security, and issues.