Hi all! I follow this tutorial to optimize ngnix . In Static File caching section can you read:
It’s possible to set expire headers for files that don’t change and are served regularly. This directive can be added to the actual Nginx server block.
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { expires 365d; } Add and remove any of the file types in the array above to match the types of files your Nginx servers.
Where should be placed this?
If i put it in http block the nginx.conf fail! And i haven’t server block in my nginx.conf.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
From the nginx documentation on the location directive:
Context:
server,location
That means that a location directive can only be placed inside a server block or another location block (which is why adding it to the http block didn’t work). Your server blocks are most likely stored in /etc/nginx/sites-enabled, so you will need to add
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
to the file in /etc/nginx/sites-enabled that contains you site’s configuration.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.