Reverse Proxy with caching
Johan Bergström
johan at bergstroem.nu
Thu Oct 15 18:38:13 MSD 2009
Hey,
On 15 okt 2009, at 16.22, Igor Sysoev wrote:
> On Thu, Oct 15, 2009 at 03:17:20PM +0200, Smrchy wrote:
>
>> Hi,
>>
>> i setup nginx and it's working great for us for static files. I'm
>> wondering
>> if nginx would be suited for the following scenario:
>>
>> We have an application server that has a lot of .php files and even
>> more
>> static files (.gif, .jpg etc).
>>
>> Can i put nginx in front of if like a proxy but have nginx cache
>> the static
>> files (everything except the .php stuff). So that only .php
>> requests reach
>> the server and the static files will be cached on the nginx machine
>> once the
>> get retrieved from the upstream server.
>
> First, you may separate static files from PHP:
>
> server {
>
> location ~ \.(gif|jpg|png)$ {
> root /data/www;
> }
>
> location ~ \.php$ {
> proxy_pass http://backend;
> }
>
> However, you have to retrieve the files by yourself.
>
> Second, you may use mirror on demand:
>
> server {
>
> location ~ \.(gif|jpg|png)$ {
> root /data/www;
> error_page 404 = @fetch;
> }
>
> location @fetch {
> internal;
>
> proxy_pass http://backend;
> proxy_store on;
> proxy_store_access user:rw group:rw all:r;
> proxy_temp_path /data/temp;
>
> root /data/www;
> }
>
> location ~ \.php$ {
> proxy_pass http://backend;
> }
>
> And finally, you may use proxy cache:
You could also add the cache purge patch to your stack if you need to
invalidate cached content: http://labs.frickle.com/nginx_cache_purge/
(applies to 0.8.x)
>
> proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:
> 10m
> inactive=24h max_size=1g;
> server {
>
> location ~ \.(gif|jpg|png)$ {
> proxy_pass http://backend;
> proyx_cache STATIC;
> proyx_cache_valid 200 1d;
> proxy_cache_use_stale error timeout invalid_header updating
> http_500 http_502 http_503 http_504;
> }
>
> location ~ \.php$ {
> proxy_pass http://backend;
> }
>
>
> --
> Igor Sysoev
> http://sysoev.ru/en/
>
More information about the nginx
mailing list