ISPManager, nginx and expires
Learn how to configure Expires headers in nginx when using ISPManager to enhance your site's caching efficiency.
Is your server using the popular software stack of ISPManager control panel, Apache web server, and nginx as a www accelerator? Note that nginx does not return Expires headers by default. While it might not always be critical for documents generated by the PHP interpreter, serving static data with such a header is desirable, allowing visitors’ browsers to cache content more effectively.
There are two methods to specify the Expires header:
-
Per Site Configuration: If you have a few sites, open
nginx.confin a text editor (for Linux systems, it is usually located in/etc/nginx/; for FreeBSD, it is in/usr/local/etc/nginx/). Locate theserver {}block for your virtual host. In this block, find thelocationsection for processing static documents and addexpires Xd, replacingXwith the desired number of days. For instance,expires 7dinstructs the browser to cache images and CSS/JS files for one week.Your location block should look like this:
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { root /var/www/username/data/www/usernamesite.ru; access_log /var/www/nginx-logs/usernamesite isp; access_log /var/www/httpd-logs/usernamesite.ru.access.log; error_page 404 = @fallback; expires 7d; } -
Global Configuration for All Virtual Servers: To have the Expires parameter set for static files across all virtual servers, create the file
/usr/local/ispmgr/etc/server.templwith the following content:location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { expires 7d; }After making this change, reload the panel using
killall ispmgr, create a new website via ISPManager, and check that the Expires parameter is correctly configured in the newly created site’snginx.conf.
Documentation Links:
Need Help?
Our support team is available 24/7 to assist you with any questions or issues.
Contact Support