OpenResty服务器入门

OpenResty简介

OpenResty(又称:ngx_openresty) 是一个基于 NGINX 的可伸缩的 Web 平台,由中国人章亦春发起,提供了很多高质量的第三方模块。

OpenResty 是一个强大的 Web 应用服务器,Web 开发人员可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,更主要的是在性能方面,OpenResty可以 快速构造出足以胜任 10K 以上并发连接响应的超高性能 Web 应用系统。

360,UPYUN,阿里云,新浪,腾讯网,去哪儿网,酷狗音乐等都是 OpenResty 的深度用户。

OpenResty安装

ubuntu下安装依赖

apt-get install libreadline-dev libpcre3-dev libssl-dev perl

如果你的系统是 Centos 或 RedHat 可以使用以下命令:

yum install readline-devel pcre-devel openssl-devel perl
wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz   # 下载
tar xzvf ngx_openresty-1.9.7.1.tar.gz       # 解压
cd ngx_openresty-1.9.7.1/ 
./configure
gmake 
gmake install

如果在./configure过程中报了如下错

[root@localhost ngx_openresty-1.9.7.1]# ./configure 
platform: linux (linux)
cp -rp bundle/ build
cd build
cd LuaJIT-2.1-20151219
Can't exec "cc": 没有那个文件或目录 at ./configure line 588.
gmake TARGET_STRIP=@: CCDEBUG=-g CC=cc PREFIX=/usr/local/openresty/luajit
==== Building LuaJIT 2.1.0-beta1 ====
gmake -C src
gmake[1]: cc:命令未找到
gmake[1]: 进入目录“/root/ngx_openresty-1.9.7.1/build/LuaJIT-2.1-20151219/src”
gmake[1]: cc:命令未找到
gmake[1]: cc:命令未找到
gmake[1]: cc:命令未找到
gmake[1]: cc:命令未找到
gmake[1]: cc:命令未找到
Makefile:262: *** Unsupported target architecture。 停止。
gmake[1]: 离开目录“/root/ngx_openresty-1.9.7.1/build/LuaJIT-2.1-20151219/src”
gmake: *** [default] 错误 2
ERROR: failed to run command: gmake TARGET_STRIP=@: CCDEBUG=-g CC=cc PREFIX=/usr/local/openresty/luajit

执行如下命令

yum install gcc

默认情况下程序会被安装到 /usr/local/openresty 目录,你可以使用 ./configure --help 查看更多的配置选项。

hello world入门

[root@localhost ~]# mkdir /home/www
[root@localhost ~]# cd /home/www/
[root@localhost www]# mkdir {logs,conf}

在conf目录下新建nginx.conf,内容如下:

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

启动OpenResty

[root@localhost conf]# cd /home/www/
[root@localhost www]# /usr/local/openresty/nginx/sbin/nginx -p `pwd` -c conf/nginx.conf 
[root@localhost www]# curl http://localhost:9000
<p>Hello, World!</p>

或者浏览器访问
在这里插入图片描述
相关站点
OpenResty 英文官网:http://openresty.org/
OpenResty 中文官网:http://openresty.org/cn/
Nginx 维基官网:http://wiki.nginx.org/
Lua 入门教程:Lua 入门教程

发布了1201 篇原创文章 · 获赞 289 · 访问量 209万+

猜你喜欢

转载自blog.csdn.net/huangbaokang/article/details/104777772