nginx配置支持memcache,但不支持写,支持读,所以读取部分由程序设置,整个代码如下

nginx的server段配置如下:

#将静态文件放入memcache

location ~* \.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
                root /usr/share/nginx/html;
                set $memcached_key $uri;
                memcached_pass 127.0.0.1:11211;
                error_page 404 = @goto404;
        }

#从后端程序设置缓存
        location @goto404{
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$fastcgi_script_name;
                include        fastcgi_params;
                rewrite ^(.*)? /goto.php?q=$1 break;
        }

goto.php源码如下:
define("PUBLIC_DIR", '/usr/share/nginx/html');
$file = $_GET['q'];

if( file_exists( PUBLIC_DIR . $file ) ){
    $memcache = new Memcache;
    $memcache->addserver("127.0.0.1", 11211);
    $value = file_get_contents( PUBLIC_DIR . $file );
    $memcache->set($file, $value, 0, 60000);
    header("Location: {$file}");
    
}else{
    header("Status: 404 Not Found");    
}

nginx下使用memcache的更多相关文章

  1. CentOS下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)

    一.源码包准备 服务器端主要是安装memcache服务器端下载:http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz另外,Memca ...

  2. Linux下的Memcache安装 和 安装Memcache的PHP扩展

    一.首先安装服务端memcached 1.下载libevent与memcache软件包. 下载memcached: wget http://memcached.org/latestwget http: ...

  3. 安全防范:nginx下git引发的隐私泄露问题

    安全防范:nginx下git引发的隐私泄露问题 1   安全事件 最近阿里云服务器后台管理系统中收到一条安全提示消息,系统配置信息泄露: http://my.domain.com/.git/confi ...

  4. 如何在Nginx下配置PHP程序环境

    1.nginx与PHP的关系 首先来看nginx与php的关系, FastCGI的关系(而不是像apache那样安装成nginx的模块) FastCGI的意思是, 快速的通用网关接口:CGI Comm ...

  5. nginx下目录浏览及其验证功能配置记录

    工作中常常有写不能有网页下载东西的需求,在Apache下搭建完成后直接导入文件即可达到下载/显示文件的效果;而Nginx的目录列表功能默认是关闭的,如果需要打开Nginx的目录列表功能,需要手动配置, ...

  6. Windows下的Memcache安装 linux下的Memcache安装

    linux下的Memcache安装: 1. 下载 memcache的linux版本,注意 memcached 用 libevent 来作事件驱动,所以要先安装有 libevent. 官方网址:http ...

  7. Windows下的Memcache安装

    Windows下的Memcache安装: 1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached2. 在终端(也即cmd命令界面)下输入 'c:\memca ...

  8. Nginx下css的链接问题

    放在 Nginx 下的网页代码,在链接外部 css 文件时,可能出现没有链接成功的问题.需要在 nginx.conf 里的 http 下添加一行. http { include mime.types;

  9. Nginx下WordPress的Rewrite

    最近接触WP Super Cache,该插件要求固定链接必须是重写的,故用到Rewrite. 我的是这样配置的: /usr/local/nginx/conf/rewrite/wordpress.con ...

随机推荐

  1. FileUpload之FileItem

    转自:http://asialee.iteye.com/blog/706079 FileItem类主要是封装了一个File Item或者是FormItem,它的主要的方法如下,需要说明的是对于Form ...

  2. AndroidStudio

    Google官方的Android集成开发环境(IDE = Integrated Development Environment),Eclipse + Adt插件的代替者. 实用设置: android ...

  3. emacs入门

    emacs入门 复制: 用Ctrl-@ 设置起点, 然后移动光标到终点, 为了确认你的起点和终点,可以用 C-x C-x 将光标在起点和终点间切换,如果没问题了,可以用 Alt-w 来复制. 再找一个 ...

  4. unity label和图片 gui

    #pragma strict var str:String; //接收外部复制贴图 var imageTexture:Texture; private var imageWidth:int; priv ...

  5. robotium 新建 android 测试项目:

    注意:新建项目后再运行前一定要修改Manifest文件中的instrumentation 中的target package, 这个是测试的入口 1. 程序开始要通知系统我要测的app是什么 如何知道a ...

  6. Float Equal Problem

    Understand limitations of floating point representations.Never check for equality with ==. Instead, ...

  7. POJ 1724 ROADS(二维SPFA)

    题目链接 用STL实现超时了,用普通队列500+,看到spfa,反应太迟钝了. #include <cstring> #include <cstdio> #include &l ...

  8. 深入理解JVM—性能监控工具

    (转自:http://yhjhappy234.blog.163.com/blog/static/31632832201222691738865/) 我们知道,在JVM编译期和加载器,甚至运行期已经做了 ...

  9. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ERROR 2013 (HY00 ...

  10. tomcat配置虚拟目录映射

    本文主要介绍web虚拟目录映射的两种常用方法及配置默认web应用的方法 一.在Server.xml中进行配置 在<Host>元素中添加子元素<Context path=" ...