Looking at how nginx-fastCGI can be used for caching in a php app, I see the following
location ~ ^(.+\.php)(.*)$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
If this were a python app, life would be much simpler, but I don't always get to choose what I work with. I'd like to limit the caching above to only static assets, like .jpg, et. al.
In a python/django world, I could so something like
location /static/$ {
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
What I think I can do is
location ~ ^(*.jpg|*.png|*.gif)$ {
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
One more thing to mention. The static file are not in a single static
directory, rather mixed in with other directories..Hence the problem.
Will that work? Anyone have a good way of doing this?
Create a separated location block for the static files:
location ~ ^/(static/) {
root /path/to/the/static/dir;
expires max;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.