Nginx使用Memcached

10 篇文章 0 订阅

Nginx使用Memcached
	    第一步:Nginx服务器必须要安装吧 php也要安装吧 mysql无所谓 php操作memcached扩展也要安装上吧 
	    如有不懂 请参看下面的文章
	    安装Nginx+PHP  http://blog.csdn.net/qq_36030288/article/details/53858357
	    安装Memached http://blog.csdn.net/qq_36030288/article/details/52613847
	    安装PHP操作memcached的扩展  http://blog.csdn.net/qq_36030288/article/details/52614703
	  
	   第二步:修改Nginx的配置文件(我是安装上面的环境修改的)
	   启动你的memcached服务 /usr/local/memcached/bin/memcached -m 64 -p 11211 -u nobody -vv -d
	   启动你的php /usr/local/src/php/sbin/php-fpm  
	   vim usr/local/src/nginx/conf/nginc.conf
	   在server中加上一段代码 如果不懂请看 location定位的用法(http://blog.csdn.net/qq_36030288/article/details/54576449)
	  
	  location / {
              set $memcached_key $uri;
              memcached_pass memcacheserver;
              error_page 404 /callback.php;
      }
      在你的nginx中html目录创建一个callback.php 这个页面的内容自己模拟一下
      如: 
       //获取uri
    $uri = $_SERVER['REQUEST_URI'];
    //new一个memcache对象出来
    $memcache = new Memcache;
    $memcache->addServer('127.0.0.1', 11211);
    $num = rand(1,999).$uri.'not use databases';
    $memcache->add($uri,$num );
    echo 'This is a',$uri,'sb memcache';

配置文件所有内容如下:

#user  nobody;
worker_processes  2;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    #日志的格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #显示目录	 
    autoindex on;
    autoindex_exact_size on;
    autoindex_localtime on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
       # location / {
       #     root   html;
       #     index  index.html index.htm;
       # }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        #简单配置一下nginx使用memcache后面有第三方模块解决算法的问题
	    location / {
		set $memcached_key "$uri";
		root html;
		memcached_pass 127.0.0.1:11211;
		error_page 404 /callback.php;
	}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #这里是配置nginx把请求交给php进程进行处理返回
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值