基于Ngnix的应用服务器-OpenResty

jopen 8年前

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

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

可以到上面的网站下载。

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

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路径:

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

启动Nginx服务器:

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

验证服务是否可用:

curl http://localhost:8080/

是不是很简单啦?


来自: http://my.oschina.net/u/2306127/blog/476872