Answer the question
In order to leave comments, you need to log in
How to configure Nginx + Apache 2 caching?
There is a website hosted. You need to bring it to the top in Google Page Speed (no need to spit, that's what the client wants). The site runs on Nginx + Apache 2. I tried to insert the following structure into .htaccess :
<FilesMatch ".(gif|jpg|jpeg|png|ico|js|css|ttf|woff|woff2)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
server {
location ~* ^.+\.(jpg|jpeg|gif|png|ico|js|css|ttf|woff|woff2)$ {
expires 1w;
add_header Cache-Control private;
}
}
Answer the question
In order to leave comments, you need to log in
in /etc/nginx/nginx.conf paste:
proxy_cache_path /tmp/nginx_static levels=1:2 keys_zone=static_cache:30m max_size=100m inactive=60m use_temp_path=off;
proxy_cache static_cache;
proxy_cache_revalidate on;
proxy_cache_lock on;
proxy_cache_valid 200 304 60m;
add_header X-Cache-Status $upstream_cache_status;
add_header Cache-Control "private";
add_header Cache-Control max-age=3600;
An example of caching, if you don't want to cache anything then proxy_cache_bypass $cookie_nocache;
proxy_cache_path /etc/nginx/cache keys_zone=cache:30m;
upstream backend {
server 127.0.0.1:8088 max_fails=4 fail_timeout=43s;
}
location / {
proxy_pass http://backend;
proxy_cache cache;
proxy_cache_valid 40s;
}
location / {
proxy_pass http://backend;
proxy_cache cache;
proxy_cache_valid 40s;
}
location ~* \.php$ {
proxy_cache_bypass $cookie_nocache;
proxy_pass http://backend;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question