Acelera tu web con Nginx como caché de proxy inverso

¿Que es una caché de Proxy Inverso?

¿Por que Nginx?

Montando la infraestructura

Instalar Nginx

sudo apt-get install nginx

Configurar el servidor web

mkdir /var/www/assets
server {
listen 81;
server_name {{tu ip o subdominio}};
access_log /var/log/nginx/static-server.log;

location ~* \. (?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 12h;
root /var/www/assets;
add_header Cache-Control "public";
}
}

Configurar el proxy caché

#/etc/nginx/sites-enabled/caching-server
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=assets_zone:10m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";
server {
listen 80;
server_name {{tu ip o subdominio}};
access_log /var/log/nginx/caching-server.log;
location /static/ {
proxy_cache assets_zone;
add_header X-Proxy-Cache $upstream_cache_status;
include proxy_params;
proxy_pass http://localhost:81/;
}
}

Enlaces relacionados

--

--

--

Full Stack Web Developer — adrianalonso.es

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrián Alonso

Adrián Alonso

Full Stack Web Developer — adrianalonso.es

More from Medium

JWT Keys and RingCentral API Connections

Event Driven Microservice for dummies

S3 Server Side Logging query — Part 1 of N

Build REST API with Apigee and gRPC