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.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
From the nginx documentation on the
location
directive:That means that a
location
directive can only be placed inside aserver
block or anotherlocation
block (which is why adding it to thehttp
block didn’t work). Your server blocks are most likely stored in/etc/nginx/sites-enabled
, so you will need to addto the file in
/etc/nginx/sites-enabled
that contains you site’s configuration.