Setting expires headers with Plesk 11.5 and nginx

I’ve been spending this morning optimizing the website in terms of load times in Browsers, and one key element of that is sending the correct expires headers to allow Browsers to cache the data.

Now, as of Plesk 11.5, you can edit nginx settings via the Control Panel, but this isn’t always straight forward, so I thought I’d write a small tutorial.

In the Control Panel:

  1. Select your Domain
  2. Click Web Server Settings
  3. Scroll down to nginx settings
  4. If you have “Serve static files directly by nginx” checked (which I recommend), you’ll need to remove the file extensions you’re going to use below, such as jpg,gif,…
  5. In the text box “Additional nginx directives” copy / paste the following configuration:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control “public”;
try_files $uri @fallback;

That’s it. Just hit OK and enjoy a website that sends the correct headers for your static images and CSS.


4 Comments, RSS

  1. Markus Oehler 7. September, 2013 @ 8:54 pm

    Wow, thanks. i was about to despair and turn nginx off again because i couldn’t get it to work. But if i remove the file endings from the list of static files that are served from nginx, does that mean they are proxied from apache again?

  2. Florian Jensen 7. September, 2013 @ 8:57 pm


    if you do remove them (step 4), but don’t add the additional location directive (step 5), then yes, they will be served by Apache. That’s why you should add them in Step 5 to a manual directive.

  3. Ryan Williams 19. December, 2013 @ 8:12 pm

    Gotcha to be aware of: if you disable the ‘Serve static files directly by nginx’ option — which you might very well do if you’re planning on using your own directive to handle them — Plesk doesn’t generate the @fallback variable, meaning the code above will fail.

    Leaving the box with some nonsense file type like ‘qwerty’ will successfully create the variable. This is important because without it you won’t be able to use any of the file types you specify in your directive as a root index file (e.g. if your root index file is, ‘html’ is in your directive, and you go to, you’ll get a 500 error).

    As an aside, it looks like your root index file will be served by Apache no matter what. If you want it caching (or not) you need to set that in Apache.

  4. jasa pembuatan web 30. April, 2014 @ 10:04 am

    I’ve been practicing it for my websites
    significant changes in speed
    thank you

Your email address will not be published. Required fields are marked *