Reverse Proxy with caching

infestdead nginx-forum at nginx.us
Fri Oct 30 13:59:32 MSK 2009


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;
>     }
> 

When I try using proxy_pass within location ~ something I get :
: "proxy_pass" may not have URI part in location given by regular expression, or inside named location, or inside the "if" statement, or inside the "limit_except" block in /etc/nginx/nginx.conf:52

the line is proxy_pass http://127.0.0.1:8080/;

Do you have an idea what the problem might be?

Thanks,
Ivo



> And finally, you may use proxy cache:
> 
> 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/

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,13955,18227#msg-18227






More information about the nginx mailing list