含義及理解:
OpenResty(又稱:ngx_openresty) 是一個基于 NGINX 的可伸縮的 Web 平臺,由中國人章亦春發起,提供了很多高質量的第三方模塊。
其目標是讓Web服務直接跑在Nginx服務內部,充分利用Nginx的非阻塞I/O模型,不僅僅對HTTP客戶端請求,甚至于對遠程后端諸如MYSQL,PostgreSQL,Memcached以及Redis等都進行一致的高性能響應
實驗搭建
首先關閉nginx服務(其自身已經有nginx,所以需要把nginx關閉)
nginx -s stop
解壓編譯安裝
tar zxf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1
./configure --prefix=/usr/local/openresty
gmake && gmake install
拷貝之前example.php和index.php到默認發布目錄準備測試
cd /usr/local/openresty/nginx/html
cp /usr/local/lnmp/nginx/html/index.php .
cp /usr/local/lnmp/nginx/html/example.php .
修改openresty的nginx配置文件
vim /usr/local/openresty/nginx/conf/nginx.conf
upstream memcache {server localhost:11211;keepalive 512;}location /memc {internal; # 只接收內部訪問,不接受外部http訪問。比較安全memc_connect_timeout 100ms;memc_send_timeout 100ms; ##后端服務器數據回傳時間memc_read_timeout 100ms; ##連接成功后,后端服務器響應時間set $memc_key $query_string;set $memc_exptime 300;memc_pass memcache;}location ~ \.php$ {set $key $uri$args;##http的GET方法表示get、PUT方法表示setsrcache_fetch GET /memc $key;(這兩個配置的作用是:請求php頁面時,先會去memcache中找,如果沒有,正常訪問;srcache_store PUT /memc $key; 訪問結束后將結果存到memcache,下次訪問時直接從緩存中)root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;include fastcgi.conf;}
編寫配置完畢檢測語法并開啟nginx
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx
再次對網頁進行壓力測試:
ab -c 10 -n 5000 http://172.25.11.4/index.php
ab -c 10 -n 5000 http://172.25.11.4/example.php
與之前只設定了php的memcache的網頁進行對比
發現速度會比之前只加了php的緩存更快
重點說明一下對index.php頁面的訪問,訪問速度有了明顯的差別 因為php是沒有緩存的