Hi,<div><br></div><div>Does your application server fill memcached correctly ? May be a binary / encoding problem when connecting to memcached. Or the content is stored gzipped ?</div><div><br></div><div>Regards</div><div>
<br></div><div>Bertrand</div><div><br></div><div><br><div class="gmail_quote">On Sun, Apr 22, 2012 at 19:02, Jakub Škrha <span dir="ltr"><<a href="mailto:serga@seznam.cz">serga@seznam.cz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<u></u>

  
    
  
  <div 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Î1Â0ŕ˙rs+"’UpŇI·ââ)צ$AÄ˙nˇ59¤ßƒďÝ5o ˜zU  0‚ =uŘZ¨ <br>
        ˘űE„cÓ%ćO5ʵ‚ľí“`ˆĹN͢Ţ}đâ3ĽŹaŐę摆y+)`¶¬«ů…M8ĄH.ŰvJ‡Ő»gďĺ•eĚyÁn•í} "§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 href="http://app.dp-xskrha.local:80" target="_blank">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           <a href="http://127.0.0.1:11211" target="_blank">127.0.0.1:11211</a>;<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          <a href="http://127.0.0.1:11211" target="_blank">127.0.0.1:11211</a>;<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 href="http://app.dp-xskrha.local:80" target="_blank">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>
  </div>


<br>_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br></blockquote></div><br></div>