基于Ngnix的應用服務器-OpenResty

jopen 8年前發布 | 12K 次閱讀 Web服務器

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

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!