How to use srcache_store while proxy_pass use to connect backend

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:
http://forum.nginx.org/read.php?2,223438,223438#msg-223438

Please help me on how to use srcache_store and use proxy_pass to store
data and connect to backend.

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

On Tue, Mar 6, 2012 at 1:48 AM, n1xman [email protected] 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 :slight_smile:

Thanks!
-agentzh

On Thu, Mar 8, 2012 at 1:51 PM, n1xman [email protected] wrote:

/var/log/nginx/error.log
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 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
http://wiki.nginx.org/HttpSRCacheModule#srcache_response_cache_control
for more details.

Best regards,
-agentzh

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

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

Thanks agentzh, you rock! It is working now :slight_smile:

Thanks for the quick support, it is really appreciated.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs