0

I have an nginx server setup to act as a fileserver. I want to set the expires directive on images. This is how a part of my config file looks like.

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    location ~* \.(ico|jpg|jpeg|png)$ {
        expires 1y;
    }
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

I get the following error when I reload config - "Location directive not allowed here".

Can someone tell me what the right syntax for this is?

Thanks in advance.

EDIT : Found the answer myself. Added it in a comment. Closing this.

1 Answer 1

0

location is valid only within a server block, not within the parent http block. You'll need to put this config inside your server blocks.

1
  • Yeah after some digging around, I edited the sites-enabled/default file to add the expires header inside a server block. Thanks anyway
    – ryan
    Jun 20, 2012 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .