# Nginx use memc

**URL:** <https://www.ruby-forum.com/t/nginx-use-memc/212107>\
**Category:** NGINX\
**Created:** [September 22, 2011, 11:25am UTC](https://www.ruby-forum.com/t/nginx-use-memc/212107 "2011-09-22T11:25:35Z")\
**Posts on this page:** 2\
**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:** [September 22, 2011, 11:25am UTC](https://www.ruby-forum.com/t/nginx-use-memc/212107/1 "2011-09-22T11:25:35Z")

</div>

Hello!  
Encountered in the use of memc such a problem, I do not know how to  
solve. In the nginx configuration file and php file using memc, can be  
normal cache. However, if the cache of php file include jump statement,  
such as @header, then jump failure. How to solve this problem?  
nginx.conf  
server {  
…  
location ~ /async/(.\*) {  
set\_md5 $md5  
$host$request\_uri;  
set $memc\_key $md5;  
memc\_pass memcbackend;  
memc\_flags\_to\_last\_modified on;  
memc\_connect\_timeout 30s;  
memc\_send\_timeout 30s;  
memc\_read\_timeout 30s;  
access\_log off;  
expires max;  
error\_page 404 = /async/index.php?$query\_string ;  
}  
…  
}  
php file /async/index.php

\<?php $url = "http://www.baidu.com"; @header ( "HTTP/1.1 301 Moved Permanently" ); @header ( "Location: " . $url ); exit(); $m = new Memcached(); $m-\>addServer('192.168.3.101', 3000); $m-\>setOption(Memcached::OPT\_COMPRESSION, false); $time = time(); $urlInfo = parse\_url($\_SERVER ['REQUEST\_URI']); $key = $\_SERVER ['SERVER\_NAME'].$\_SERVER ['REQUEST\_URI']; echo $key; $m-\>set(md5($key), $time ,60); ?\>

If the access address [http://www.test.com/async/test.php](http://www.test.com/async/test.php)  
/async/ directory is not include test.phpd file, it will be 404  
redirected to /async/ index.php, but the @header in /async/index.php  
will not be effective.  
How to solve this problem? Thank you very much!

Posted at Nginx Forum:

> **[nginx use memc](https://forum.nginx.org/read.php?2,215565,215565#msg-215565)**
>
> Hello! Encountered in the use of memc such a problem, I do not know how to solve. In the nginx configuration file and php file using memc, can be normal cache. However, if the cache of php file include jump statement, such as @header, then jump...

---

<div class="post-metadata">

**Author:** ![lys0212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b3f665/32.png) [@lys0212](https://www.ruby-forum.com/u/lys0212)\
**Post date:** [September 22, 2011, 11:45am UTC](https://www.ruby-forum.com/t/nginx-use-memc/212107/2 "2011-09-22T11:45:24Z")

</div>

On Thu, Sep 22, 2011 at 5:25 PM, lys0212 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello!  
> Encountered in the use of memc such a problem, I do not know how to  
> solve. In the nginx configuration file and php file using memc, can be  
> normal cache. However, if the cache of php file include jump statement,  
> such as @header, then jump failure. How to solve this problem?

Please do not abuse the error\_page directive with ngx\_memc to do  
response caching; it’s problematic. I suggest you take a look at the  
ngx\_srcache module which can serve as a generic cache layer and can be  
used safely with backend storage modules like ngx\_memc:

```
http://wiki.nginx.org/HttpSRCacheModule

```

Regards,  
-agentzh
