[openresty]安装和入门(一)

首先推荐官网:http://openresty.org/en/

一,安装openresty包

1,安装依赖

yum install perl dos2unix

yum install pcre-devel openssl-devel gc-c++

wget https://openresty.org/download/openresty-1.11.2.1.tar.gz

解压tar zxvf openresty-1.11.2.1

./configure

gmake

gmake install

安装完成

默认的路径是/usr/local/openresty/

二 hello world 程序

参考http://openresty.org/cn/getting-started.html

Prepare directory layout

We first create a separate directory for our experiments. You can use an arbitrary directory. Here for simplicity, we just use~/work:

mkdir ~/work
cd ~/work
mkdir logs/ conf/

Note that we’ve also created the logs/ directory for logging files and conf/ for our config files.

Prepare the nginx.conf config file

Create a simple plain text file named conf/nginx.conf with the following contents in it:

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 8088;
        location / {
            default_type text/html;
            content_by_lua '
                ngx.say("<p>hello, world</p>")
            ';
        }
    }
}

If you’re familiar with Nginx configuration, it should look very familiar to you. OpenResty is just an enhanced version of Nginxby means of addon modules anyway. You can take advantage of all the exisitng goodies in the Nginx world.

Start the Nginx server

Assuming you have installed OpenResty into/usr/local/openresty (this is the default)

Then we start the nginx server with our config file this way:
/usr/local/openresty/sbin/nginx -p `pwd`/ -c conf/nginx.conf

-p 标识的是

-p prefix : set prefix path (default: /usr/local/openresty/nginx/) 路径
-c filename : set configuration file (default: conf/nginx.conf)     配置

Error messages will go to the stderr device or the default error log files logs/error.log in the current working directory.

Access our HelloWorld web service

We can use curl to access our new web service that says HelloWorld:

curl http://localhost:8088/

If everything is okay, we should get the output

<p>hello, world</p>

ab 压测一下

ab -c 10 -n 100 http://localhost:8088/

在单核阿里云的配置下:

Requests per second:    240.93 [#/sec] (mean) 还算比较高的

未完待续。。。。

发表评论

电子邮件地址不会被公开。 必填项已用*标注


*