How to setup expire headers in NGINX?

Posted February 12, 2014 7.3k views
Hi,I want to setup exprire headers for nginx but i don't know how.I searched but nothing related to this issue. Thanks

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.

Submit an Answer
4 answers
you didn't mention what expire header type you need...

Nevertheless, this is expire header for images:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 1y;
log_not_found off;

you can add this code to your vhost in /etc/nginx/sites-available/yoursite-vhost

I hope that helps
I didn't noticed I already have included some other things such as css and js files.

you can edit whatever you like though