微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[nginx]编译安装openresty

前言

OpenResty是一个基于Nginx和Lua的高性能Web平台,其内部集成了大量精良的Lua库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

版本信息

系统和应用 版本
Debian 11-amd64位
OpenResty 1.21.4.1

步骤

  1. 下载源码包并解压
wget https://openresty.org/download/openresty-1.21.4.1.tar.gz
tar xf openresty-1.21.4.1.tar.gz
  1. 编译
# apt安装依赖
apt install -y libpcre3-dev openssl libssl-dev libxml2-dev libgd-dev libxml2 libgeoip-dev libxslt-dev

cd openresty-1.21.4.1
# 以下预编译参数和Nginx的编译参数基本一致
./configure --prefix=/home/apps/openresty \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit

gmake
gmake install
  1. 启动OpenResty
/home/aps/openresty/bin/openresty
  1. 浏览器访问80端口测试
  2. (可选)验证无误后,将openresty的bin目录添加到系统环境变量PATH中

helloworld

  1. 编辑 /home/apps/openresty/Nginx/conf/Nginx.conf, 找到监听80端口的server,增加以下路由
location = /test {
    default_type 'text/plain';
    content_by_lua_block {
    	ngx.say('Hello World')
    }
}
  1. 热加载生效
openresty -s reload
  1. 测试
curl http://127.0.0.1/test

ngx.say 将数据作为响应体输出,返回给客户端,并在末尾加上一个回车符。

content_by_lua_block 的主要作用是在HTTP的内容处理阶段生成数据

参考

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐