Nginx as a caching reverse proxy to replace squid/varnish

Hey guys
the following is our current setup on the apps

but we would like to add nginx as a reverse proxy cache much like squid
or
varnish
is it possible to edit this config to enable that caching behavior or do
i
need to add another nginx in front of this set up like i would do for
squid
or varnish

if this can be done without resorting to usage of squid and varnish it
would
be nice to have the complete setup in nginx

thanks a lot

upstream backend_appname{

#start1.someserver.com
server start1.someserver.com:7810 fail_timeout=3s;
server start1.someserver.com:7811 fail_timeout=3s;
server start1.someserver.com:7812 fail_timeout=3s;
server start1.someserver.com:7813 fail_timeout=3s;

}
server {
    server_name  appname.someserver.com;

listen 80;
access_log logs/access_appname.log;
#error_log logs/error_appname.log;

    location /nginx_status {
        stub_status on;
        access_log   off;
    }

    location /static {
        root   /home/someuser/work/appname;
        expires max;
        add_header Cache-Control

public,max-age=604800,post-check=604800,pre-check=1209600;
}
location / {
root /home/someuser/work/appname;
fastcgi_pass backend_appname;
set $addr $remote_addr;

     if ($http_x_forwarded_for ~ 

“(?:^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {
set $addr $1;
}

        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_script_name;
        fastcgi_param QUERY_STRING    $query_string;
        fastcgi_param CONTENT_TYPE    $content_type;
        fastcgi_param CONTENT_LENGTH  $content_length;
        fastcgi_param REQUEST_METHOD  $request_method;
        fastcgi_param REMOTE_ADDR     $addr;
        fastcgi_param REMOTE_PORT     $remote_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_ADDR     $server_addr;
        fastcgi_param SERVER_PORT     $server_port;
        fastcgi_param SERVER_NAME     $server_name;

    }

}

On Mon, 2009-08-17 at 14:39 -0700, [email protected] wrote:

if this can be done without resorting to usage of squid and varnish it
would be nice to have the complete setup in nginx

http {
[…]

proxy_cache_path /opt/nginx/cache levels=1:2 keys_zone=one:10m;

[...]

    server {
    listen       127.0.0.1:8000;
    server_name  localhost;
    access_log  /var/log/nginx/one.access.log  main;
    location / {
        proxy_pass         http://192.168.10.10:80/;
        proxy_redirect     off;

        proxy_cache        one;
        proxy_cache_valid  200 1h;
        [...]
    }
}

Declaring cache ( proxy_cache_path ) and caching ( proxy_cache ) should
be enough.

Proxy_cache_valid in above example is used to enforce caching for
objects that have no declaration on caching.

On Mon, Aug 17, 2009 at 02:39:52PM -0700, [email protected]
wrote:

be nice to have the complete setup in nginx
server start1.someserver.com:7812 fail_timeout=3s;
location /nginx_status {
location / {
fastcgi_param QUERY_STRING $query_string;
}

}

Instead of

      set  $addr  $remote_addr;

      if ($http_x_forwarded_for ~ 

“(?:^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {
set $addr $1;
}

      fastcgi_param REMOTE_ADDR     $addr;

you should use

set_real_ip_from   0.0.0.0/32;
real_ip_header     X-Forwarded-For;

fastcgi_param REMOTE_ADDR     $remote_addr;