Setting expires headers with Plesk 11.5 and nginx

by Florian Jensen

I’ve been spending this morning optimizing the Flosoft.biz 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.

 

2 Comments to “Setting expires headers with Plesk 11.5 and nginx”

  1. 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. Hi,

    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.

Leave a Reply