openresty 概述

官网:http://openresty.org/cn/

openresty 简介

openresty基于nginx、lua的web平台,整合了大量三方模块,可直接使用,不需要手动编译

# openresty 默认安装的模块
root@7bd203df440c:/usr/local/openresty/nginx# ./sbin/nginx -V
nginx version: openresty/1.19.9.1
built with OpenSSL 1.1.1l  24 Aug 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx \
--with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include'  \--add-module=../ngx_devel_kit-0.3.1 \
--add-module=../echo-nginx-module-0.62 \
--add-module=../xss-nginx-module-0.06 \
--add-module=../ngx_coolkit-0.2 \
--add-module=../set-misc-nginx-module-0.32 \
--add-module=../form-input-nginx-module-0.12 \
--add-module=../encrypted-session-nginx-module-0.08 \
--add-module=../srcache-nginx-module-0.32 \
--add-module=../ngx_lua-0.10.20 \
--add-module=../ngx_lua_upstream-0.07 \
--add-module=../headers-more-nginx-module-0.33 \
--add-module=../array-var-nginx-module-0.05 \
--add-module=../memc-nginx-module-0.19 \
--add-module=../redis2-nginx-module-0.15 \
--add-module=../redis-nginx-module-0.3.7 \
--add-module=../ngx_stream_lua-0.0.10 \--with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' \--with-pcre-jit --with-stream \
--with-stream_ssl_module --with-stream_ssl_preread_module \
--with-http_v2_module --without-mail_pop3_module \
--without-mail_imap_module --without-mail_smtp_module \
--with-http_stub_status_module --with-http_realip_module \
--with-http_addition_module --with-http_auth_request_module \
--with-http_secure_link_module --with-http_random_index_module \
--with-http_gzip_static_module --with-http_sub_module \
--with-http_dav_module --with-http_flv_module \
--with-http_mp4_module --with-http_gunzip_module \
--with-threads --with-stream --with-http_ssl_module

配置说明

nginx.conf

# nginx.conf  --  docker-openresty
#
# This file is installed to:
#   `/usr/local/openresty/nginx/conf/nginx.conf`
# and is the file loaded by nginx at startup,
# unless the user specifies otherwise.
#
# It tracks the upstream OpenResty's `nginx.conf`, but removes the `server`
# section and adds this directive:
#     `include /etc/nginx/conf.d/*.conf;`
#
# The `docker-openresty` file `nginx.vh.default.conf` is copied to
# `/etc/nginx/conf.d/default.conf`.  It contains the `server section
# of the upstream `nginx.conf`.
#
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
##user  nobody;
#worker_processes 1;# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;# Enables or disables the use of underscores in client request header fields.# When the use of underscores is disabled, request header fields whose names contain underscores are marked as invalid and become subject to the ignore_invalid_headers directive.# underscores_in_headers off;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;# Log in JSON Format# log_format nginxlog_json escape=json '{ "timestamp": "$time_iso8601", '# '"remote_addr": "$remote_addr", '#  '"body_bytes_sent": $body_bytes_sent, '#  '"request_time": $request_time, '#  '"response_status": $status, '#  '"request": "$request", '#  '"request_method": "$request_method", '#  '"host": "$host",'#  '"upstream_addr": "$upstream_addr",'#  '"http_x_forwarded_for": "$http_x_forwarded_for",'#  '"http_referrer": "$http_referer", '#  '"http_user_agent": "$http_user_agent", '#  '"http_version": "$server_protocol", '#  '"nginx_access": true }';# access_log /dev/stdout nginxlog_json;# See Move default writable paths to a dedicated directory (#119)# https://github.com/openresty/docker-openresty/issues/119client_body_temp_path /var/run/openresty/nginx-client-body;proxy_temp_path       /var/run/openresty/nginx-proxy;fastcgi_temp_path     /var/run/openresty/nginx-fastcgi;uwsgi_temp_path       /var/run/openresty/nginx-uwsgi;scgi_temp_path        /var/run/openresty/nginx-scgi;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;include /etc/nginx/conf.d/*.conf;# Don't reveal OpenResty version to clients.# server_tokens off;
}

default.conf

# nginx.vh.default.conf  --  docker-openresty
#
# This file is installed to:
#   `/etc/nginx/conf.d/default.conf`
#
# It tracks the `server` section of the upstream OpenResty's `nginx.conf`.
#
# This config (and any other configs in `etc/nginx/conf.d/`) is loaded by
# default by the `include` directive in `/usr/local/openresty/nginx/conf/nginx.conf`.
#
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
#server {listen       80;server_name  localhost;#charset koi8-r;#access_log  /var/log/nginx/host.access.log  main;location / {root   /usr/local/openresty/nginx/html;index  index.html index.htm;}location /lua {default_type "applictaion/json";content_by_lua "ngx.say('hello gtlx')";}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   /usr/local/openresty/nginx/html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           /usr/local/openresty/nginx/html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}
}

main 指令

user *** ***                       # 定义运行ngin的用户、用户组worker_processors 2                # nginx的进程数
worker_cpu_affinity auto           # nginx的cpu亲缘性
worker_rlimit_nofile  65535        # worker进程最大可打开的文件数
worker_priority       0            # worker进程优先级
worker_shutdown_timeout  30        # 30s内无法平滑关闭,强制退出pid /var/run/nginx.pid             # 进程文件
error_log /path/error.log level    # 错误日志路径、输出级别events {worker_connections  1000       # 单个进程最大连接数,# nignx总最大连接数 = 单个进程最大连接数 * worker_processorsuse epoll                      # 使用的io模型
}

http 指令

http {include       mime.types;                     # 文件拓展名、类型映射表default_type  application/octet-stream;       # 默认文件类型underscores_in_headers off;                   # 请求头中包含underscores是否标记为无效log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';# 日志格式(名称为main)access_log  logs/access.log  main;            # 日志文件路径、使用的日志格式(上面定义的main格式)client_body_temp_path /var/run/openresty/nginx-client-body;  # 客户端请求临时文件保存路径proxy_temp_path       /var/run/openresty/nginx-proxy;        # 代理请求缓存路径gzip  on;                                     # 是否开启压缩sendfile        on;                           # 是否开启sendfile函数,默认开启tcp_nopush     on;                            # sendfile为on生效,提升网络传输效率server_tokens off;                            # 屏蔽版本号,默认不屏蔽keepalive_timeout  65;                        # tcp连接超时时间include /etc/nginx/conf.d/*.conf;             # 导入配置文件
}

server、location 指令

server {listen       80;            # 服务监听端口server_name  localhost;     # 主机名charset koi8-r;             # 编码集access_log  /var/log/nginx/host.access.log  main;   # 日志输出路径、输出格式location / {                                 # 请求路径,支持正则表达式root   /usr/local/openresty/nginx/html;  # 根目录index  index.html index.htm;}location /lua {default_type "applictaion/json";content_by_lua "ngx.say('hello gtlx')";}error_page  404              /404.html;      # 客户端错误重定向页面error_page   500 502 503 504  /50x.html;     # 服务端错误重定向页面location = /50x.html {root   /usr/local/openresty/nginx/html;}}

常用模块

内置模块:http://openresty.org/cn/components.html

三方模块搜索:

常用模块说明

LuaNginxModule:集成lua,在nginx中使用lua命令
LuaRestyUploadLibrary:http文件上传HeadersMoreNginxModule:设置请求、响应头(添加、修改、删除)lua-resty-mysql:操作mysql数据库
lua-resty-redis:操作redis数据库lua-resty-lrucache:nginx缓存
lua-resty-mlcache:nginx缓存# 动态负载均衡
ngx_http_dyups_module
nginx-upsync-module
lua-resty-balancerngx_http_auth_request_moddule:nginx鉴权

openresty 概述相关推荐

  1. OpenResty概述

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

  2. 高性能web平台【OpenResty入门与实战】

    一.OpenResty概述 1 OpenResty 背景 随着宽带网络的快速普及和移动互联网的高速发展,网站需要为越来越多的用户提供服务,处理越来越多的并发请求,要求服务器必须具有很高的性能才能应对不 ...

  3. 电商秒杀 Springboot + Redis +RocketMq +Mysql

    项目地址 https://gitee.com/noah2021/miaosha 转载,亲测可用! 测试用例 在下订单之前需要先发布对应的商品用于在Redis中生成口令避免大量请求导致服务器崩溃~~ 发 ...

  4. Nginx后端开发人员必学神器-并发编程经典之作剖析和名企热点面试v1.21.3

    概述 **本人博客网站 **IT小神 www.itxiaoshen.com Nginx官网 最新版本为1.21.3 Nginx (engine x) 是一个开源的.高性能的HTTP和反向代理web服务 ...

  5. Openresty宏观概述笔记

    最近由于项目需要学习了安全代理的相关知识,其实刚开始的时候是非常需要一个入门的介绍,大概说明下这个到底是个什么东西,能干啥,简单的原理是什么,为此我记录下我看完用完的心得,记录成笔记. 一般我们代码开 ...

  6. lua-resty-iputils, 在Openresty中,用于处理IP地址的实用程序函数

    源代码名称:lua-resty-iputils 源代码网址:http://www.github.com/hamishforbes/lua-resty-iputils lua-resty-iputils ...

  7. java openresty 调用_Openresty使用zlib解压缩response body

    产品需要对当前的所有接口进行统计数据,其中需要边缘层返回需要用到的response body的状态码以及信息 概述 目前后台返回的response body既有压缩又有不压缩,所以导致处理数据需要进行 ...

  8. 基于nginx开发下的OpenResty开发指南构建百万级别并发的Web应用

    OpenResty是一个基于Nginx的高性能Web平台,能够方便地搭建处理超高并发的动态Web应用.Web服务和动态网关.与现有的其他开发语言/环境相比,OpenResty 有着高性能.高灵活性.易 ...

  9. Apache OpenWhisk架构概述

    本文讲的是Apache OpenWhisk架构概述[编者的话]Apache OpenWhisk是一个开源FaaS平台.现在,AWS Lambda是FaaS最流行的实现. 在开源组件的选择中,OpenW ...

最新文章

  1. word文档墨迹工具的笔不能用_云师之策|找到合适的工具实现理想的在线教学效果...
  2. 【PAT乙级】1020 月饼 (25 分)
  3. 【Linux网络编程】并发服务器之多进程模型
  4. 实现一个用户取过的数据不被其他用户取到
  5. 记录遇到的Python陷阱和注意点
  6. mysql aa ap_商务移动首选 华硕便携式2in1无线AP
  7. Web API 路由 [二] Attribute Routing
  8. [实验手册]用2500路由器做自动安装实验
  9. linux重定向文件容加时间,[单选] linux系统,把当前日期重定向到/tmp/date文件中,并不想覆盖原来的内容,下面正确的操作是()。...
  10. 使用阿里云加速器解决docker下载镜像太慢的问题
  11. IDEA 导包快捷键
  12. redis在php下面的命令大全
  13. SolidWorks软件远程安装协助
  14. 如何使用linux command line 利用Entrez Direct下载NCBI数据
  15. Unity3d 双阈值解决临界值跳跃的问题
  16. Gym - 101492 F. Hitting the target(几何)
  17. C语⾔核⼼基础知识之printf
  18. 校招22届大疆 嵌入式面经/23届投递可私戳内推!
  19. 继续教育计算机考试试题,第四批继续教育计算机考试试题.doc
  20. 转: X264码率控制总结1——ABR,CQP,CRF

热门文章

  1. Python在股票池选取中的应用
  2. python图片增强 曝光度,亮度
  3. 使用WebAudio实现音频音波可视化
  4. 斯卡博洛市集 Scarborough Fair
  5. 【基础入门题010】互质勾股数组
  6. 经典游戏“大富翁4”存档文件修改器Rich4Editor下载
  7. 3u8633还在飞吗_5月14日3U8633航班在成都迫降危险性有多大?附刘机长专访
  8. 阿尔法GO的缺陷(宽度搜索解法)(C++)
  9. JAVA学习笔记(三十九)-打印流
  10. python按钮虚化,深度学习与图像处理实例:人像背景虚化与背景替换