<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    <tt><font size="-1">Hi,<br>
        <br>
        I have problem with nginx and memcached responses such as
        text/html or <br>
        application/json and </font><font size="-1">I will be glad for
        any help</font><font size="-1">. Thanks.<br>
        <br>
        My idea is:<br>
        -First request on nginx server (reverse proxy memcached server)<br>
        -Try if I have memcached response (memcached run on same server
        as <br>
        nginx)<br>
        -If not pass request to application server<br>
        -Application server makes response<br>
        -Stores response in to memcached<br>
        -And for next same request nginx hit response from memcached and
        return <br>
        to client.<br>
        <br>
        But the problem is, when the application server stores response
        to <br>
        memcached (data in memcached are stored good and corectly) and
        NGINX hit <br>
        the request in memcached, but return totaly wrong hashed
        content.<br>
        <br>
        For example:<br>
        First request, ngingx didnt find response in memcached, pass to
        <br>
        application server, and here is response ... good and correct
        JSON.<br>
        ------- Headers<br>
        HTTP/1.0 200 OK<br>
        Date: Sun, 22 Apr 2012 16:13:58 GMT<br>
        Server: Apache/2.2.16 (Debian)<br>
        X-Powered-By: PHP/5.3.3-7+squeeze8<br>
        cache-control: no-cache<br>
        x-debug-token: 4f942e4dee10b<br>
        Content-Length: 476<br>
        Connection: close<br>
        Content-Type: application/json<br>
        -------- Content<br>
[{"id":10,"title":"Cinema","url":"cinema","articles":null},{"id":2,"title":"Computers","url":"computer","articles":null},{"id":8,"title":"Foto","url":"foto","articles":null},{"id":12,"title":"Literature","url":"literature","articles":null},{"id":4,"title":"Music","url":"music","articles":null},{"id":18,"title":"Society","url":"society","articles":null},{"id":16,"title":"Sport","url":"sport","articles":null},{"id":6,"title":"Travelling","url":"travelling","articles":null}]<br>
        <br>
        But for the second request, when NGINX find response in
        memcached, NGINX <br>
        serves response totaly wrong.<br>
        -------- Headers<br>
        Connection:keep-alive<br>
        Content-Length:164<br>
        Content-Type:application/json<br>
        Date:Sun, 22 Apr 2012 16:17:15 GMT<br>
        Server:nginx/0.7.67<br>
        -------- Content<br>
        xśu󏌆ŕ˙rs+"扷pŇI封)爪$A˙nˇ59みƒď5o ˜zU亹0倎=uŘZ <br>
        ˘űE刢%ćO5Ę祩ľ頁`ˆĹN˘Ţ}đ3ĽŹaŐęć憜y+)`冬ů匨8ĄH.ŰvJŐ籫ďĺ昬Ěy羘曧}"4ďűDfęŮ姰ţ甠
        <br>
        ť<br>
        <br>
        With text/html I have exactly the same problem. Do you have
        anybody any <br>
        idea plese? Here is my nginx configuration:<br>
        <br>
        # nginx virtual host from sites-available linked to
        sites-enabled<br>
        server {<br>
        牋 listen牋牋牋牋 80;<br>
        牋 server_name牋牋 dp-xskrha.local;<br>
        牋 access_log牋牋 /var/log/nginx/dp-xskrha/access.log;<br>
        牋 error_log牋牋牋 /var/log/nginx/dp-xskrha/error.log;<br>
        <br>
        牋 # Static content, images, css, js<br>
        牋 location ~* <br>
        ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|avi|mp3)$
        <br>
        {<br>
        牋牋牋 proxy_redirect牋牋牋牋 off;<br>
        牋牋牋 proxy_pass牋牋牋牋牋牋 <a class="moz-txt-link-freetext" href="http://app.dp-xskrha.local:80">http://app.dp-xskrha.local:80</a>;<br>
        牋牋牋 proxy_set_header牋牋牋 Host牋牋牋牋牋牋 $host;<br>
        牋牋牋 proxy_set_header牋牋牋 X-Real-IP牋牋牋牋 $remote_addr;<br>
        牋牋牋 proxy_set_header牋牋牋 X-Forwarded-For牋
        $proxy_add_x_forwarded_for;<br>
        牋牋牋 proxy_cache牋牋牋牋牋牋 dp-xskrha-static;<br>
        牋牋牋 roxy_cache_valid牋牋牋 200 10m;<br>
        牋 }<br>
        <br>
        牋 # Model api json<br>
        牋 location /model-api {<br>
        牋牋牋 default_type牋牋牋牋牋牋 application/json;<br>
        牋牋牋 set $memcached_key牋牋牋 $uri;<br>
        牋牋牋 memcached_pass牋牋牋牋牋 127.0.0.1:11211;<br>
        牋牋牋 error_page牋牋牋牋牋牋牋 404 =200 @fallback;<br>
        牋 }<br>
        <br>
        牋 # Dynamic content, all rest uri<br>
        牋 location / {<br>
        牋牋牋 default_type牋牋牋牋牋 text/html;<br>
        牋牋牋 charset牋牋牋牋牋牋牋牋 utf-8;<br>
        牋牋牋 set $memcached_key牋牋 $uri;<br>
        牋牋牋 memcached_pass牋牋牋牋 127.0.0.1:11211;<br>
        牋牋牋 error_page牋牋牋牋牋牋 404 =200 @fallback;<br>
        牋牋 }<br>
        <br>
        牋 # Memcached fallback for proxy pass<br>
        牋 location @fallback {<br>
        牋牋牋 proxy_set_header牋牋牋牋牋 Host牋牋牋牋牋牋 $host;<br>
        牋牋牋 proxy_set_header牋牋牋牋牋 X-Real-IP牋牋牋
        $remote_addr;<br>
        牋牋牋 proxy_set_header牋牋牋牋牋 X-Forwarded-For
        $proxy_add_x_forwarded_for;<br>
        牋牋牋 proxy_redirect牋牋牋牋牋牋 off;<br>
        牋牋牋 proxy_pass牋牋牋牋牋牋牋牋
        <a class="moz-txt-link-freetext" href="http://app.dp-xskrha.local:80">http://app.dp-xskrha.local:80</a>;<br>
        牋牋 }<br>
        }<br>
        <br>
        <br>
        #nginx.conf<br>
        user www-data;<br>
        worker_processes 1;<br>
        <br>
        error_log /var/log/nginx/error.log;<br>
        pid牋牋牋 /var/run/nginx.pid;<br>
        <br>
        events {<br>
        牋 worker_connections 1024;<br>
        牋 multi_accept on;<br>
        }<br>
        <br>
        http {<br>
        牋 include牋牋牋 /etc/nginx/mime.types;<br>
        <br>
        牋 access_log牋 /var/log/nginx/access.log;<br>
        <br>
        牋 sendfile牋牋牋 on;<br>
        牋 tcp_nopush牋牋 on;<br>
        <br>
        牋 #keepalive_timeout 0;<br>
        牋 keepalive_timeout 65;<br>
        牋 tcp_nodelay牋牋牋 on;<br>
        <br>
        牋 gzip on;<br>
        牋 gzip_disable "MSIE [1-6]\.(?!.*SV1)";<br>
        <br>
        牋 # proxy settings<br>
        牋 proxy_cache_path /data/nginx/cache levels=1:2
        keys_zone=dp-xskrha-static:10m <br>
        牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋 inactive=24h
        max_size=1g;<br>
        <br>
        牋 include /etc/nginx/conf.d/*.conf;<br>
        牋 include /etc/nginx/sites-enabled/*;<br>
        }<br>
        <br>
        Thank you very much, for Your response :)<br>
        <br>
        Jacob</font></tt>
  </body>
</html>