dragonhaze
dragonhaze

Reputation: 319

Setup NGINX as client-side content caching server

I'm trying to setup NGINX as local caching server, to cache all of the web content I load, and then return it back to me, to speed up webpages loading. Official NGINX docs offer proxy_cache directive to solve this problem. I set up my server as proxy, by example. Here's my config:


worker_processes  1;
events {}
http {
    proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=1g;
    server {
        location / {
            proxy_cache my_cache;
            proxy_cache_revalidate on;
            proxy_cache_min_uses 1;
            proxy_cache_use_stale error timeout updating http_500 http_502
                              http_503 http_504;
            proxy_cache_background_update on;
            proxy_cache_lock on;

            proxy_pass http://localhost:1416;
        }
    }
}

NGINX starts fine with this config, but when I set up a proxy in Firefox to http://localhost:1416, it starts saying that proxy server refuses connection. I want to know, what's my misconfigurations there and am I following a right way of setting up NGINX as local client-side caching server?

Upvotes: 0

Views: 558

Answers (1)

Joe
Joe

Reputation: 31057

The configuration you have here:

proxy_pass http://localhost:1416;

means that, for each request that matches location /, Nginx will proxy it to localhost:1416. As your server block doesn't specify a port, Nginx will listen on the default of 80.

Unless you have something configured elsewhere, nothing is listening on port 1416. You could test this with:

curl --proxy http://localhost:1416 http://www.example.com/

which will likely fail with:

Failed to connect to localhost port 1416: Connection refused

While Nginx is often used as a reverse proxy, it is not a good choice for a general purpose caching proxy. Consider, for example, Apache Traffic Server or Squid.

Upvotes: 1

Related Questions