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 入门教程

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄宝康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值