Welcome! Log In Create A New Profile

Advanced

Re: Reverse Proxy with caching

Johan Bergström
October 15, 2009 10:46AM
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/
>
Subject Author Posted

Reverse Proxy with caching

Smrchy October 15, 2009 09:24AM

Re: Reverse Proxy with caching

任晓磊 October 15, 2009 09:46AM

Re: Reverse Proxy with caching

Igor Sysoev October 15, 2009 10:28AM

Re: Reverse Proxy with caching

Johan Bergström October 15, 2009 10:46AM

Re: Reverse Proxy with caching

Smrchy October 15, 2009 11:42AM

Re: Reverse Proxy with caching

infestdead October 30, 2009 06:59AM

Re: Reverse Proxy with caching

infestdead October 30, 2009 07:08AM

Re: Reverse Proxy with caching

Igor Sysoev October 30, 2009 07:16AM

Re: Reverse Proxy with caching

ridres83 October 16, 2009 01:20PM

Re: Reverse Proxy with caching

avery October 19, 2009 06:06PM

Re: Reverse Proxy with caching

Maxim Dounin October 19, 2009 06:58PM

Re: Reverse Proxy with caching

Rafa Pedroche April 27, 2010 06:40PM

Re: Reverse Proxy with caching

Rafa Pedroche April 28, 2010 03:16AM

Re: Reverse Proxy with caching

nfn October 22, 2009 01:26PM

Re: Reverse Proxy with caching

avery October 22, 2009 04:28PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 227
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready