Welcome! Log In Create A New Profile

Advanced

Re: Nginx and memcached response

Jakub Škrha
April 22, 2012 01:40PM
On 22.4.2012 19:17, nginx-request@nginx.org wrote:
> ------------------------------
>
> Message: 2
> Date: Sun, 22 Apr 2012 18:48:06 +0200
> From: Jakub<lists@ruby-forum.com>
> To: nginx@nginx.org
> Subject: NGINX and wrong memcached output
> Message-ID:<89b67bf90e128310fea0429f089719aa@ruby-forum.com>
> Content-Type: text/plain; charset=UTF-8
>
> Hi,
>
> At first let me tell my application was developped under PHP with
> Symfony2, but I guess my problem is about nginx and memcached and not
> about PHP. As I can see here is good community about nginx and I will be
> glad for any help.
>
> I have problem with nginx and memcached responses such as text/html or
> application/json. My idea is:
> -First request on nginx server (reverse proxy memcached server)
> -Try if I have memcached response (memcached run on same server as
> nginx)
> -If not go to application server
> -Application server makes response
> -Stores response in to memcached
> -And for next same request nginx hit response from memcached and return
> to client.
>
> But the problem is, when the application server stores response to
> memcached (data in memcached are stored good and corectly) and NGINX hit
> the request in memcached, but return totaly wrong hashed content.
>
> For example:
> First request, ngingx didnt find response in memcached, pass to
> application server, and here is response ... good and correct JSON.
> ------- Headers
> HTTP/1.0 200 OK
> Date: Sun, 22 Apr 2012 16:13:58 GMT
> Server: Apache/2.2.16 (Debian)
> X-Powered-By: PHP/5.3.3-7+squeeze8
> cache-control: no-cache
> x-debug-token: 4f942e4dee10b
> Content-Length: 476
> Connection: close
> Content-Type: application/json
> -------- Content
> [{"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}]
>
> But for the second request, when NGINX find response in memcached, NGINX
> serves totaly wrong.
> -------- Headers
> Connection:keep-alive
> Content-Length:164
> Content-Type:application/json
> Date:Sun, 22 Apr 2012 16:17:15 GMT
> Server:nginx/0.7.67
> -------- Content
> x?u?1?0??rs+"?Up?I???)??$A??n?59?????5o ?zU??0??=u?Z?
> ??E?c?%?O5??????`??N???}??3??a?????y+)`?????M8?H.?vJ???g???e?y?n??}?"?4???Df??????_?
> ?
>
> With text/html I have exactly the same problem. Do you have anybody any
> idea plese? Here is my nginx configuration:
>
> # nginx virtual host from sites-available
> server {
> listen 80;
> server_name dp-xskrha.local;
> access_log /var/log/nginx/dp-xskrha/access.log;
> error_log /var/log/nginx/dp-xskrha/error.log;
>
> # Static content, images, css, js
> location ~*
> ^.+\.(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)$
> {
> proxy_redirect off;
> proxy_pass http://app.dp-xskrha.local:80;
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For
> $proxy_add_x_forwarded_for;
> proxy_cache dp-xskrha-static;
> roxy_cache_valid 200 10m;
> }
>
> # Model api json
> location /model-api {
> default_type application/json;
> set $memcached_key $uri;
> memcached_pass 127.0.0.1:11211;
> error_page 404 =200 @fallback;
> }
>
> # Dynamic content, all rest uri
> location / {
> default_type text/html;
> charset utf-8;
> set $memcached_key $uri;
> memcached_pass 127.0.0.1:11211;
> error_page 404 =200 @fallback;
> }
>
> # Memcached fallback for proxy pass
> location @fallback {
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For
> $proxy_add_x_forwarded_for;
> proxy_redirect off;
> proxy_pass http://app.dp-xskrha.local:80;
> }
> }
>
>
> #nginx.conf
> user www-data;
> worker_processes 1;
>
> error_log /var/log/nginx/error.log;
> pid /var/run/nginx.pid;
>
> events {
> worker_connections 1024;
> multi_accept on;
> }
>
> http {
> include /etc/nginx/mime.types;
>
> access_log /var/log/nginx/access.log;
>
> sendfile on;
> tcp_nopush on;
>
> #keepalive_timeout 0;
> keepalive_timeout 65;
> tcp_nodelay on;
>
> gzip on;
> gzip_disable "MSIE [1-6]\.(?!.*SV1)";
>
> # proxy settings
> proxy_cache_path /data/nginx/cache levels=1:2
> keys_zone=dp-xskrha-static:10m
> inactive=24h max_size=1g;
>
> include /etc/nginx/conf.d/*.conf;
> include /etc/nginx/sites-enabled/*;
> }
>
> Thank you very much, for Your response :)
>
> Jacob
>
Date: Sun, 22 Apr 2012 19:17:29 +0200
From: Bertrand Paquet<bpaquet@octo.com>
To:nginx@nginx.org
Subject: Re: Nginx and memcached response
Message-ID:
<CAPs0E=02iCkH4bGM6UqryPNS3cqhvxGp4SWt7NDAe6FNFeb1Jg@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

Does your application server fill memcached correctly ? May be a binary /
encoding problem when connecting to memcached. Or the content is stored
gzipped ?

Regards

Bertrand


Hi,

yes the server fill memcached correctly. For example, if I store on
simple JSON value, it stores correctly. Or when I store plain text,
there is not any problem. Just if store to memcached some content with
headers. Maybe there is problem with headers. I will try some other
memcached client than the the application server is using. But I am not
sure if the problem is in store process. I think there is a problem with
nginx read proces.

Thank you very much

Jacob

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx and memcached response

Jakub Škrha April 22, 2012 01:04PM

Re: Nginx and memcached response

bpaquet April 22, 2012 01:18PM

Re: Nginx and memcached response

Jakub Škrha April 22, 2012 01:40PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 161
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready