基于Ngnix的应用服务器-OpenResty

Nginx是普遍使用的Web服务器和负载均衡服务器,由俄罗斯人开发。基于Nginx的Lua支持的OpenResty天然也是短小精悍,这个是由中国人章亦春开发和维护。中国程序员愈来愈了不得!html

OpenResty的官方主页在:http://openresty.org/。虽然基于Lua的接受面没有Java/.NET/Python之类的接受面广,但其短小精悍,基于其实现应用服务是一个极佳的想法。
nginx

能够到上面的网站下载。
程序员

安装也是极其简单的,标准的Linux软件包的方式,像下面这样就搞定了:shell

tar xzvf ngx_openresty-VERSION.tar.gz
cd ngx_openresty-VERSION/
./configure
make
make install

快速建立一个应用:服务器

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

#建立配置文件
gedit conf/nginx.conf

建立一个配置文件conf/nginx.conf,内容以下:负载均衡

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

设定Nginx路径:curl

PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH

启动Nginx服务器:网站

nginx -p `pwd`/ -c conf/nginx.conf

验证服务是否可用:lua

curl http://localhost:8080/

是否是很简单啦?url

相关文章
相关标签/搜索