Welcome! Log In Create A New Profile

Advanced

How to cache .php files using proxy_cache?

Posted by fz_andy 
How to cache .php files using proxy_cache?
July 09, 2009 01:50AM
Hi,

I've been trying to cache my images from the backend php api. e.g. getImage/php. But I am unable to do it.
I am able to all kinds of static file types (e.g. html, png, css, etc). I am wondering if nginx is by default bypasses the cache of .php files? If it is, is there any configuration to override that? Thx.

my http configuration is as below:

[code]
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
#keepalive_timeout 65;

#gzip on;


gzip on;
gzip_min_length 1000;
gzip_types text/plain application/xml text/css application/x-javascript;
gzip_disable "MSIE [1-6]";


proxy_cache_path /var/www/cache/statics levels=1:2 keys_zone=one:10m;
proxy_cache_path /var/www/cache/fs levels=1:2 keys_zone=two:10m;
proxy_cache_path /var/www/cache/test levels=1:2 keys_zone=three:10m;

server {
listen 80;
server_name localhost;
server_name_in_redirect off;

# proxy_store_access user:rw group:rw all:rw;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;



location / {
expires 2592000;

proxy_cache three;
proxy_cache_methods POST;
proxy_cache_valid 365d;
proxy_pass http://localhost:8080;

break;
}

}
[/code]



Andy
Re: How to cache .php files using proxy_cache?
July 09, 2009 12:28PM
It should cache php pages. Do they have a "Cache-Control" header? There may be something in there that's preventing the cache from storing the page.

To test you could add

[code]
proxy_ignore_headers Cache-Control;
[/code]

This only works on nginx 0.7.54 and later. I wouldn't recommend leaving that in a production environment but is a reasonable way to test.

--
Jim Ohlstein
Re: How to cache .php files using proxy_cache?
July 10, 2009 01:18AM
Thx ^^

It works now!

Andy
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 85
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready