OpenResty实现Nginx服务内部加速,openrestynginx


一、OpenResty是什么

OpenResty是一个基于Nginx与Lua的高性能Web平台,其内部集成了大量精良的Lua库,第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性及高的动态Web应用,Web服务器和动态网关。OpenResty通过汇聚各种设计精良的Nginx模块,从而将Nginx有效地变成一个强大的通用Web应用平台。这样一来,Web开发人员和系统工程师可以使用Lua脚本语言调动Nginx支持的各种C以及Lua模块,快速构造出足以胜任10K乃至1000K以上单机并发连接的高性能Web应用系统
OpenResty的目标是让你的Web服务直接跑到Nginx服务内部,充分利用Nginx的非阻塞I/O模型,不仅仅对HTTP客户端请求,甚至于远程后端诸如MySQL、PostgreSQL、Memcached以及Redis等都进行一致的高性能响应。

二、开始实现

1、将之前/usr/local/lnmp/nginx/关闭,因为我们要安装可以替代普通nginx的openresty

[root@server1 ~]# nginx -s stop

2、下载opensresty源码包,解压并源码编译

[root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz
[root@server1 ~]# cd openresty-1.13.6.1
 [root@server1 openresty-1.13.6.1]# ./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --add-module=/root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42
[root@server1 openresty-1.13.6.1]# gmake && gmake install

3、修改配置文件

[root@server1 ~]# cd /opt/nginx/nginx/conf
[root@server1 conf]# vim nginx.conf
 17 http {
 18         upstream memcache {
 19         server localhost:11211;
 20         keepalive 512;
 21         }
 22     include       mime.types;
 23     default_type  application/octet-stream;
 
 51         location /memc {
 52                         internal;
 53                         memc_connect_timeout 100ms;
 54                         memc_send_timeout 100ms;
 55                         memc_read_timeout 100ms;
 56                         set $memc_key $query_string;
 57                         set $memc_exptime 300;
 58                         memc_pass memcache;
 59                         }
 60 
 61         #error_page  404              /404.html;

78         location ~ \.php$ {
 79             root           html;
 80             set $key $uri$args;
 81             srcache_fetch GET /memc $key;
 82             srcache_store PUT /memc $key;
 83             fastcgi_pass   127.0.0.1:9000;
 84             fastcgi_index  index.php;
 85         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 86             include        fastcgi.conf;
 87         }
[root@server1 conf]#  /opt/nginx/nginx/sbin/nginx -t	#检测语法
[root@server1 conf]#  /opt/nginx/nginx/sbin/nginx		#开启nginx服务
[root@server1 conf]#  /opt/nginx/nginx/sbin/nginx -s reload	#重启服务

访问测试:172.25.66.1

4、将之前的php页面copy一份到openresty中

[root@server1 ~]# cd /opt/nginx/nginx/conf
[root@server1 conf]# cp /usr/local/lnmp/nginx/conf/nginx.conf .
[root@server1 conf]# cd ..
[root@server1 nginx]# cd html/
[root@server1 html]# cp /usr/local/lnmp/nginx/html/example.php .
[root@server1 html]# cp /usr/local/lnmp/nginx/html/index.php  .

5、此时开启的接听端口有:

[root@server1 conf]# netstat -antpl


开始做压力测试:

[root@foundation66 kiosk]# ab -c 10 -n 1000 http://172.25.66.1/index.php

[root@foundation66 kiosk]# ab -c 10 -n 1000 http://172.25.66.1/example.php


和之前的php+memcache相比,快了好几倍

相关内容

    暂无相关文章