Setting expires headers with Plesk 11.5 and nginx
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:
- Select your Domain
- Click Web Server Settings
- Scroll down to nginx settings
- 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,…
- 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.