OpenResty(也称为 ngx_openresty)是一个全功能的 Web 应用服务器,结合一些优秀的Nginx 模块,OpenResty 有效地把 Nginx 服务器转变为一个强大的 Web 应用服务器。
openresty的配置
首先停止nginx
nginx -s stop
1.获取安装包
openresty-1.13.6.1.tar.gz
2.解压
[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]# ls
bundle COPYRIGHT README.markdown util
configure patches README-win32.txt
3.编译安装
[root@server1 openresty-1.13.6.1]# ./configure
[root@server1 openresty-1.13.6.1]# gmake && gmake install
4.将发布页复制过来
cd /usr/local/openresty/nginx/html
cp /usr/local/lnmp/nginx/html/index.php .
cp /usr/local/lnmp/nginx/html/example.php .
5.修改配置文件
[root@server1 html]# cd ../conf/
[root@server1 conf]# vim nginx.conf
1
2 user nginx nginx;
3 worker_processes auto;
4
5 #error_log logs/error.log;
6 #error_log logs/error.log notice;
7 #error_log logs/error.log info;
8
9 #pid logs/nginx.pid;
10
11
12 events {
13 worker_connections 1024;
14 }
15
16
17 http {
18 include mime.types;
19 default_type application/octet-stream;
20 upstream memcache {
21 server localhost:11211;
22 keepalive 512;
23 }
48 location / {
49 root html;
50 index index.php index.html index.htm;
51 }
52
70 location /memc {
71 internal;
72 memc_connect_timeout 100ms;
73 memc_send_timeout 100ms;
74 memc_read_timeout 100ms;
75 set $memc_key $query_string;
76 set $memc_exptime 300;
77 memc_pass memcache;
78 }
79
80 location ~ \.php$ {
81 set $key $uri$args;
82 srcache_fetch GET /memc $key;
83 srcache_store PUT /memc $key;
84 root html;
85 fastcgi_pass 127.0.0.1:9000;
86 fastcgi_index index.php;
87 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
88 include fastcgi.conf;
89 }
90
检测配置文件
[root@server1 conf]# cd ..
[root@server1 nginx]# cd sbin/
[root@server1 sbin]# ./nginx -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
6.启动nginx,查询进程
[root@server1 sbin]# ./nginx
[root@server1 sbin]# ps ax
7.测试
此时是openresty开启的nginx在运行,在主机上:
ab -c 10 -n 5000 http://172.25.80.1/index.php
会出现31.831s,此时服务的软件是openresty/1.13.6.1
接下来,我们将openresty的nginx关闭,将nginx打开
[root@server1 sbin]# ls
nginx
[root@server1 sbin]# ./nginx -s stop
[root@server1 sbin]# cd
[root@server1 ~]# nginx
会出现33.254s,此时服务的软件是nginx
显然比较慢了