Unidad 10.2: Reverse proxy

Nginx como puerta de entrada a tu aplicacion

Author

Diego Saavedra

Published

Feb 2, 2026

Unidad 10.2: Reverse proxy

Introduccion

Un reverse proxy recibe trafico HTTP/HTTPS y lo reenvia a un servicio interno (por ejemplo, una app escuchando en 127.0.0.1:3000).

Objetivos de aprendizaje

  • Configurar un server block simple
  • Proxyear a un backend local
  • Validar con curl y logs

Crear un server block (sitio)

Este ejemplo proxy a http://127.0.0.1:3000.

BASH
1$ sudo tee /etc/nginx/sites-available/app.conf >/dev/null <<'EOF'
server {
  listen 80;
  server_name app.local;

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
}
EOF


2$ sudo ln -sf /etc/nginx/sites-available/app.conf /etc/nginx/sites-enabled/app.conf


3$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


4$ sudo systemctl reload nginx
1
tee + heredoc crea el server block.
2
ln -sf habilita el sitio (symlink a sites-enabled).
3
nginx -t valida sintaxis y configuracion.
4
systemctl reload nginx aplica cambios.

Probar con Host header

BASH
1$ curl -i -H 'Host: app.local' http://127.0.0.1/
HTTP/1.1 502 Bad Gateway
Server: nginx/1.24.0 (Ubuntu)
1
curl -H Host prueba el server block; si el backend no existe, veras 502 (esto es evidencia de que Nginx esta encaminando).
TipRECOMENDACION

Para el laboratorio real, levanta un backend primero (por ejemplo un contenedor o una app en 3000) y repite el curl hasta ver 200.

Casos de uso: - Node/FastAPI/Django/Golang detras de Nginx.

Cuando aplicar: - Cuando necesitas TLS, rate limiting o logs frontales.

Code Appendix