Guys,
Happy new year
This is my first post in this forum.
Today i have found a problem in configuring nginx for caching html files that are generating from Apache FPM engine.
I first used this code and added it to /var/www/vhosts/system/DOMAINNAME/conf/vhost_nginx.conf.
fastcgi_cache_path /tmp/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
server_name "DOMAINNAME";
root "/var/www/vhosts/DOMAINNAME/httpdocs";
set $no_cache 0;
if ($request_uri ~* "/(admin/)")
{
set $no_cache 1;
}
location ~ ^/(index)\.php(/|$) {
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 60m; # Only cache 200 responses, cache for 60 minutes
fastcgi_cache_methods GET HEAD; # Only GET and HEAD methods apply
add_header X-Fastcgi-Cache $upstream_cache_status;
fastcgi_cache_bypass $no_cache; # Don't pull from cache based on $no_cache
fastcgi_no_cache $no_cache; # Don't save to cache based on $no_cache
# Regular PHP-FPM stuff:
include fastcgi.conf; # fastcgi_params for nginx < 1.6.1
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:///var/www/vhosts/system/DOMAINNAME/php-fpm.sock;
fastcgi_index index.php;
}
}
but nginx throws an error that this code is not allowed in this directive.
Then i tried to insert it in this path /etc/nginx/conf.d
It works and ngnix can load the configuration but when i check the header i see nginx didn't cache any html files.
Can you help me to solve it? how can i setup nginx to cache output of dynamic php files ?
Happy new year
This is my first post in this forum.
Today i have found a problem in configuring nginx for caching html files that are generating from Apache FPM engine.
I first used this code and added it to /var/www/vhosts/system/DOMAINNAME/conf/vhost_nginx.conf.
fastcgi_cache_path /tmp/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
server_name "DOMAINNAME";
root "/var/www/vhosts/DOMAINNAME/httpdocs";
set $no_cache 0;
if ($request_uri ~* "/(admin/)")
{
set $no_cache 1;
}
location ~ ^/(index)\.php(/|$) {
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 60m; # Only cache 200 responses, cache for 60 minutes
fastcgi_cache_methods GET HEAD; # Only GET and HEAD methods apply
add_header X-Fastcgi-Cache $upstream_cache_status;
fastcgi_cache_bypass $no_cache; # Don't pull from cache based on $no_cache
fastcgi_no_cache $no_cache; # Don't save to cache based on $no_cache
# Regular PHP-FPM stuff:
include fastcgi.conf; # fastcgi_params for nginx < 1.6.1
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:///var/www/vhosts/system/DOMAINNAME/php-fpm.sock;
fastcgi_index index.php;
}
}
but nginx throws an error that this code is not allowed in this directive.
Then i tried to insert it in this path /etc/nginx/conf.d
It works and ngnix can load the configuration but when i check the header i see nginx didn't cache any html files.
Can you help me to solve it? how can i setup nginx to cache output of dynamic php files ?