# How to use srcache\_store while proxy\_pass use to connect backend

**URL:** <https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578>\
**Category:** NGINX\
**Created:** [March 5, 2012, 6:48pm UTC](https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578 "2012-03-05T18:48:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 5, 2012, 6:48pm UTC](https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578/1 "2012-03-05T18:48:56Z")

</div>

Hi,

I can’t store data while I’m using proxy\_pass to connect to the backend  
if we can’t find data on the memcached. srcache\_fetch probes the  
memcached but since no data, it connect to the backend and get the  
correct data but not executing the srcache\_store. Here is my config.

```
    location /memc {
            internal;
            memc_connect_timeout 500ms; # 500 miliseconds
memc_send_timeout 5000ms; # 5 seconds
memc_read_timeout 500ms; # 500 miliseconds

set $memc_key $query_string;
            set $memc_exptime 3600;

memc_pass 127.0.0.1:11211;

```

}

location /webservice {  
set $key $http\_host$request\_uri;  
srcache\_fetch GET /memc $key;  
add\_header X-Cached-From srcache-memcached;

# store the content!

```
    srcache_store_statuses 200 201 301 302 404 503 502;
    srcache_store PUT /memc $key;

```

# if it is not found we go to the backend

```
    proxy_pass http://remoteserver;

```

}

I use nginx-1.0.10. and I should be able to use proxy\_pass to get  
backend data while store data on the cache…?

If I comment the proxy\_pass, srcache\_store triggered and stored the 502  
status page as it can’t connect to the backend.

Please help me on how to use srcache\_store and use proxy\_pass to store  
data and connect to backend.

Thanks in advance.

Posted at Nginx Forum:

> **[How to use srcache\_store while proxy\_pass use to connect backend](https://forum.nginx.org/read.php?2,223438,223438#msg-223438)**
>
> Hi, I can't store data while I'm using proxy\_pass to connect to the backend if we can't find data on the memcached. srcache\_fetch probes the memcached but since no data, it connect to the backend and get the correct data but not executing the...

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [March 5, 2012, 7:24pm UTC](https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578/2 "2012-03-05T19:24:22Z")

</div>

Please help me on how to use srcache\_store and use proxy\_pass to store  
data and connect to backend.

Posted at Nginx Forum:

> **[Re: How to use srcache\_store while proxy\_pass use to connect backend](https://forum.nginx.org/read.php?2,223438,223443#msg-223443)**
>
> Hi, I can't store data while I'm using proxy\_pass to connect to the backend if we can't find data on the memcached. srcache\_fetch probes the memcached but since no data, it connect to the backend and get the correct data but not executing the...

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [March 7, 2012, 2:27am UTC](https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578/3 "2012-03-07T02:27:23Z")

</div>

On Tue, Mar 6, 2012 at 1:48 AM, n1xman [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I can’t store data while I’m using proxy\_pass to connect to the backend  
> if we can’t find data on the memcached. srcache\_fetch probes the  
> memcached but since no data, it connect to the backend and get the  
> correct data but not executing the srcache\_store.

Can you enable the debug logs in your nginx build and paste the  
relevant logs here? To enable the debug logs, just re-compile your  
nginx with the --with-debug configure option, and also use the “debug”  
log level in your “error\_log” config directive in your nginx.conf.

Also telling me the outputs of the “/path/to/your/nginx -V” command  
and “uname -a” command on your side may also be helpful 🙂

Thanks!  
-agentzh

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [March 8, 2012, 7:02am UTC](https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578/4 "2012-03-08T07:02:22Z")

</div>

On Thu, Mar 8, 2012 at 1:51 PM, n1xman [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> /var/log/nginx/error.log  
> [http://pastebin.com/W7Jk3sq8](http://pastebin.com/W7Jk3sq8)

The line 182 in your error.log snippet gives you the answer:

2012/03/08 10:49:10 [debug] 20521#0: \*11 srcache\_store skipped due to  
response header Cache-Control

That is, the response from your backend server explicitly prohibits  
caching via the Cache-Control response header. And the line 191 in  
your error.log snippet confirms this:

Cache-Control: no-cache

If you want to enforce caching in this very case, just turn on the  
srcache\_store\_no\_cache config directive, like

```
srcache_store_no_cache on;

```

See [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpSRCacheModule#srcache_store_no_cache) for  
more details.

Or turn off the srcache\_response\_cache\_control config directive to  
make ngx\_srcache ignore the Cache-Control response header altogether:

```
srcache_response_cache_control off;

```

See

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

for more details.

Best regards,  
-agentzh

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [March 8, 2012, 6:51am UTC](https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578/5 "2012-03-08T06:51:50Z")

</div>

Hi agentzh,

Thanks for helping me out. I build a fresh setup and enabled the debug  
and followings are the details.

nginx.debug -V  
nginx: nginx version: nginx/1.0.9  
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)  
nginx: TLS SNI support disabled  
nginx: configure arguments: --prefix=/etc/nginx/  
–sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf  
–error-log-path=/var/log/nginx/error.log  
–http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid  
–lock-path=/var/run/nginx.lock  
–http-client-body-temp-path=/var/cache/nginx/client\_temp  
–http-proxy-temp-path=/var/cache/nginx/proxy\_temp  
–http-fastcgi-temp-path=/var/cache/nginx/fastcgi\_temp  
–http-uwsgi-temp-path=/var/cache/nginx/uwsgi\_temp  
–http-scgi-temp-path=/var/cache/nginx/scgi\_temp --user=nginx  
–group=nginx --with-http\_ssl\_module --with-http\_realip\_module  
–with-http\_addition\_module --with-http\_sub\_module  
–with-http\_dav\_module --with-http\_flv\_module --with-http\_mp4\_module  
–with-http\_gzip\_static\_module --with-http\_random\_index\_module  
–with-http\_secure\_link\_module --with-http\_stub\_status\_module  
–with-mail --with-mail\_ssl\_module --with-file-aio --with-ipv6  
–with-debug --with-cc-opt=‘-O2 -g -m32 -march=i386 -mtune=generic  
-fasynchronous-unwind-tables’  
–add-module=/usr/local/n1xman/rpmbuild/BUILD/nginx-1.0.9/contrib/memc-nginx-module-4007350  
–add-module=/usr/local/n1xman/rpmbuild/BUILD/nginx-1.0.9/contrib/echo-nginx-module-6c1f553  
–add-module=/usr/local/n1xman/rpmbuild/BUILD/nginx-1.0.9/contrib/simpl-ngx\_devel\_kit-24202b4  
–add-module=/usr/local/n1xman/rpmbuild/BUILD/nginx-1.0.9/contrib/set-misc-nginx-module-e6a54ab  
–add-module=/usr/local/n1xman/rpmbuild/BUILD/nginx-1.0.9/contrib/srcache-nginx-module-86e7a18

uname -a  
Linux abmx-test 2.6.18-194.el5PAE #1 SMP Tue Mar 16 22:00:21 EDT 2010  
i686 i686 i386 GNU/Linux

cat /etc/nginx/nginx.conf

user nginx;  
worker\_processes 1;

error\_log /var/log/nginx/error.log warn;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
log_format main '$remote_addr - $remote_user [$time_local]

```

“$request” ’  
'$status $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

```

}

cat /etc/nginx/conf.d/default.conf  
upstream my\_mem {  
server 127.0.0.1:11211;  
}

server {  
listen 80;  
server\_name localhost;

```
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log debug;

    default_type application/json;

```

location = /memc {  
internal;

```
    memc_connect_timeout 100ms;
    memc_send_timeout 100ms;
    memc_read_timeout 100ms;

    set $memc_key $query_string;
    set $memc_exptime 300;

    memc_pass my_mem;
}

location /mix2 {
    proxy_pass http://data.directfn.com;
    set $key $args;
    srcache_fetch GET /memc $key;
    srcache_store PUT /memc $key;
    srcache_store_statuses 200 301 302 404;

    }

location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
}

#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}

```

}

/var/log/nginx/error.log  
[http://pastebin.com/W7Jk3sq8](http://pastebin.com/W7Jk3sq8)

Posted at Nginx Forum:

> **[Re: How to use srcache\_store while proxy\_pass use to connect backend](https://forum.nginx.org/read.php?2,223438,223618#msg-223618)**
>
> Hi, I can't store data while I'm using proxy\_pass to connect to the backend if we can't find data on the memcached. srcache\_fetch probes the memcached but since no data, it connect to the backend and get the correct data but not executing the...

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [March 8, 2012, 7:32am UTC](https://www.ruby-forum.com/t/how-to-use-srcache-store-while-proxy-pass-use-to-connect-backend/217578/6 "2012-03-08T07:32:07Z")

</div>

Thanks agentzh, you rock! It is working now 🙂

Thanks for the quick support, it is really appreciated.

Posted at Nginx Forum:

> **[Re: How to use srcache\_store while proxy\_pass use to connect backend](https://forum.nginx.org/read.php?2,223438,223621#msg-223621)**
>
> Hi, I can't store data while I'm using proxy\_pass to connect to the backend if we can't find data on the memcached. srcache\_fetch probes the memcached but since no data, it connect to the backend and get the correct data but not executing the...
