RejectedSoftware Forums

Sign up

[OT] nginx and caching

Hi. I'm trying to enable some caching, but it's not working out too well.

Looking at some online tutorials and how-tos gives some information on
how to do this, but when I try to implement this, it seems it no longer
loads the resources I'm trying to cache.

Has anyone successfully enabled caching of css, images etc on nginx and
can give me some tips? This is parts of my config right now:

server {
  #gzip on etc
  location / {
    #proxy pass my vibe application etc
    proxy cache my-vibe-app;
    proxy_cache_validate 30m;
    expires 30m;

    location ~* \.(css|png|js)$ {
      expires 30m;
      proxy_set_header Cache-Control public;
      add_header Cache-Control public;
    }
  }
}

I've tried several variations of the above, but they all seem to break
loading these resources.

Any tips on how to set up caching on nginx+vibe?

Re: [OT] nginx and caching

Ages ago I remember using something like this:

server
{
    listen 80   default_server;
    server_name example.com

    location /static/
    {
        root    /home/www-example/static/;
        expires 1d;
    }

    location /
    {
        proxy_pass       http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
    }
}

tl; dr: simply defining expires for location of static did the trick

Re: [OT] nginx and caching

On 08/26/2014 02:26 AM, Dicebot wrote:

Ages ago I remember using something like this:

server
{
    listen 80   default_server;
    server_name example.com

    location /static/
    {
        root    /home/www-example/static/;
        expires 1d;
    }

    location /
    {
        proxy_pass       http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
    }
}

tl; dr: simply defining expires for location of static did the trick

Thanks, that worked.

Re: [OT] nginx and caching

On 08/26/2014 10:53 AM, simendsjo wrote:

On 08/26/2014 02:26 AM, Dicebot wrote:

Ages ago I remember using something like this:

server
{
    listen 80   default_server;
    server_name example.com

    location /static/
    {
        root    /home/www-example/static/;
        expires 1d;
    }

    location /
    {
        proxy_pass       http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
    }
}

tl; dr: simply defining expires for location of static did the trick

Thanks, that worked.

Well.. The caching worked, but it seems it then doesn't find the
resources.. Very strange.