Question
How do I exclude files or URLs from being cached when using EA-NGINX?
Answer
Requests for dynamic content to your website should include cache control headers to ensure that they are not cached by EA-NGINX. If you do not, the server may return cached responses that do not apply to the current user.
In most cases, the website software you are using will set headers that disables the NGINX cache where required; such as when accessing the admin area. However, it may also be required to have other files or URLs where NGINX caching does not occur. This can be configured at the server-level via an NGINX include file, or managed locally via the .htaccess.
- Open the
.htaccessfile for the website. -
Add the appropriate configuration for the for the files/URL to exclude.
CONFIG_TEXT: <If "%{REQUEST_URI} =~ m#/my-url/#">
<IfModule mod_headers.c>
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
</IfModule>
</If>Note: In the above example, requests to this website's
/my-urlwill not be cached by NGINX.
- Access the server's command line as the
rootuser via SSH or Terminal in WHM. -
Create the include file for the domain.
# touch /etc/nginx/conf.d/users/$cpuser/$domain.tld/include.conf
Note:
$cpuseranddomain.tldmust be replaced with the cPanel user's username and the website's domain name, respectively. - Open the newly created include file in your preferred text editor.
-
Add the appropriate configuration for the files/URL to exclude. For example:
CONFIG_TEXT: location ^~ /my-url {
expires -1;
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}Note: In the above example, requests to this website's
/my-urlwill not be cached by NGINX. - Save the changes and exit the text editor.
-
Rebuild the NGINX configuration for the cPanel user.
# /usr/local/cpanel/scripts/ea-nginx config $cpuser
Note:
$cpusermust be replaced with the cPanel user's username.
Comments
0 comments
Article is closed for comments.