## 概述
OpenResty 是一個基于 Nginx 的全功能 Web 平臺,它集成了大量精心設計的 Nginx 模塊,以及大量的 Lua 庫。在使用 OpenResty 時,有兩種主要的包管理工具:opm 和 LuaRocks。
## OPM
OPM(OpenResty Package Manager)是 OpenResty 官方提供的包管理工具,可以用來從中心 OPM 包服務器上面安裝社區貢獻的第三方模塊。專門用于安裝和管理 OpenResty 的 Lua 模塊。它是官方推薦使用的工具,因為它確保了模塊與 OpenResty 的兼容性,并優化了性能,在你安裝好 OpenResty 之后,就可以直接使用。
顯示命令幫助
```
# opm --help
opm [options] command package...
Options:
-h
--help Print this help.
--install-dir=PATH Install into the specified PATH directory instead of the system-wide
OpenResty installation tree containing this tool.
--cwd Install into the current working directory under ./resty_modules/
instead of the system-wide OpenResty installation tree containing
this tool.
Commands:
build Build from the current working directory a package tarball ready
for uploading to the server.
clean ARGUMENT... Do clean-up work. Currently the valid argument is "dist", which
cleans up the temporary files and directories created by the "build"
command.
info PACKAGE... Output the detailed information (or meta data) about the specified
packages. Short package names like "lua-resty-lock" are acceptable.
get PACKAGE... Fetch and install the specified packages. Fully qualified package
names like "openresty/lua-resty-lock" are required. One can also
specify a version constraint like "=0.05" and ">=0.01".
list List all the installed packages. Both the package names and versions
are displayed.
remove PACKAGE... Remove (or uninstall) the specified packages. Short package names
like "lua-resty-lock" are acceptable.
search QUERY... Search on the server for packages matching the user queries in their
names or abstracts. Multiple queries can be specified and they must
fulfilled at the same time.
server-build Build a final package tarball ready for distribution on the server.
This command is usually used by the server to verify the uploaded
package tarball.
update Update all the installed packages to their latest version from
the server.
upgrade PACKAGE... Upgrade the packages specified by names to the latest version from
the server. Short package names like "lua-resty-lock" are acceptable.
upload Upload the package tarball to the server. This command always invokes
the build command automatically right before uploading.
For bug reporting instructions, please see:
<https://openresty.org/en/community.html>
Copyright (C) Yichun Zhang (agentzh). All rights reserved.
```
通過`opm search [包名] `搜索包名和包的簡介
```
# opm search lua-resty-http
aptise/peter_sslers-lua-resty openresty ssl certificate routines for peter_sslers SSL Certificate manager
aptise/lua-resty-peter_sslers openresty ssl certificate routines for peter_sslers SSL Certificate manager
....
tomas/lua-resty-elasticsearch ElasticSearch client for OpenResty / ngx_lua.
agentzh/lua-resty-http Lua HTTP client cosocket driver for OpenResty/ngx_lua
```
通過`opm get [包名] `安裝擴展包
```
# opm get ledgetech/lua-resty-http
* Fetching ledgetech/lua-resty-http
Downloading https://opm.openresty.org/api/pkg/tarball/ledgetech/lua-resty-http-0.17.1.opm.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 20622 100 20622 0 0 28133 0 --:--:-- --:--:-- --:--:-- 28095
Package ledgetech/lua-resty-http 0.17.1 installed successfully under /usr/local/openresty/site/ .
```
通過`opm info [包名] `查看已安裝包的詳細信息
```
# opm info lua-resty-http
Name : lua-resty-http
Version : 0.17.1
Abstract : Lua HTTP client cosocket driver for OpenResty/ngx_lua
Author : James Hurst
Account : ledgetech
Code Repo : https://github.com/ledgetech/lua-resty-http
License : BSD 2-Clause "Simplified" or "FreeBSD" license
Original Work : yes
```
通過`opm list`查看已經安裝的包列表
```
# opm list
agentzh/lua-resty-http 0.09
```
通過`opm upgrade [包名]`包升級
```
# opm upgrade lua-resty-http
* Fetching agentzh/lua-resty-http > 0.09
Package agentzh/lua-resty-http 0.09 is already the latest version.
```
通過`opm remove [包名]`移除已經安裝的包
```
# opm remove lua-resty-http
Package agentzh/lua-resty-http 0.09 removed successfully.
```
安裝包存儲位置
```
cd /usr/local/openresty/site/lualib/resty
# ls
http.lua http_headers.lua
```
### 使用
lua-resty-http 是一個基于OpenResty的HTTP客戶端庫,用于在Lua中進行HTTP請求和響應的處理。
`openresty.tinywan.com.conf`配置文件
```
server {
listen 80;
server_name openresty.tinywan.com;
location /lua_http_test {
default_type "text/html";
lua_code_cache off;
content_by_lua_file conf/lua/lua_http_test.lua;
}
}
```
`lua_http_test.lua` 腳本
```
local httpc = require("resty.http").new()
-- Single-shot requests use the `request_uri` interface.
local res, err = httpc:request_uri("https://www.workerman.net/u/Tinywan", {
method = "GET",
body = "name=Tinywan&age=24",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
},
ssl_verify = false,
})
if not res then
ngx.log(ngx.ERR, "request failed: ", err)
return
end
local status = res.status
local length = res.headers["Content-Length"]
local body = res.body
ngx.say(res.body)
```
通過curl腳本測試請求打印結果
```html
$ curl -i http://openresty.tinywan.com/lua_http_test
HTTP/1.1 200 OK
Server: openresty/1.17.8.2
Date: Wed, 17 Jul 2024 09:42:10 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" href="/favicon.ico" />
<link href="https://cdn.workerman.net/css/bootstrap.min.css?v=20211126" rel="stylesheet">
<link href="https://cdn.workerman.net/css/main.css?v=20240705" rel="stylesheet">
<script src="https://cdn.workerman.net/js/jquery.min.js"></script>
<script src="https://cdn.workerman.net/js/bootstrap.min.js?v=20211126"></script>
<script src="https://cdn.workerman.net/js/functions.js?v=20220507"></script>
<script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
<title>Tinywan的主頁-分享-workerman社區</title>
</head>
...
</body>
</html>
```
## LuaRocks
LuaRocks 是一個通用的 Lua 模塊管理工具,可以用來安裝 Lua 模塊。然而,使用 luarocks 與 OpenResty 并不是官方推薦的方式,因為 luarocks 安裝的模塊可能會阻塞 OpenResty 的事件循環,導致性能下降。
詳細使用請看這里 [Openresty如何使用lualocks包管理器安裝使用Lua包](https://mp.weixin.qq.com/s/8fVUKW53vG8E3v8aOX_lWw)
- 設計模式系列
- 工廠方法模式
- 序言
- Windows程序注冊為服務的工具WinSW
- 基礎
- 安裝
- 開發規范
- 目錄結構
- 配置
- 快速入門
- 架構
- 請求流程
- 架構總覽
- URL訪問
- 容器和依賴注入
- 中間件
- 事件
- 代碼層結構
- 四個層次
- 路由
- 控制器
- 請求
- 響應
- 數據庫
- MySQL實時同步數據到ES解決方案
- 阿里云DTS數據MySQL同步至Elasticsearch實戰
- PHP中的MySQL連接池
- PHP異步非阻塞MySQL客戶端連接池
- 模型
- 視圖
- 注解
- @SpringBootApplication(exclude={DataSourceAutoConfiguration.calss})
- @EnableFeignClients(basePackages = "com.wotu.feign")
- @EnableAspectJAutoProxy
- @EnableDiscoveryClient
- 錯誤和日志
- 異常處理
- 日志處理
- 調試
- 驗證
- 驗證器
- 驗證規則
- 擴展庫
- 附錄
- Spring框架知識體系詳解
- Maven
- Maven和Composer
- 構建Maven項目
- 實操課程
- 01.初識SpringBoot
- 第1章 Java Web發展史與學習Java的方法
- 第2章 環境與常見問題踩坑
- 第3章 springboot的路由與控制器
- 02.Java編程思想深度理論知識
- 第1章 Java編程思想總體
- 第2章 英雄聯盟的小案例理解Java中最為抽象的概念
- 第3章 徹底理解IOC、DI與DIP
- 03.Spring與SpringBoot理論篇
- 第1章 Spring與SpringBoot導學
- 第2章 Spring IOC的核心機制:實例化與注入
- 第3章 SpringBoot基本配置原理
- 04.SprinBoot的條件注解與配置
- 第1章 conditonal 條件注解
- 第2章 SpringBoot自動裝配解析
- 05.Java異常深度剖析
- 第1章 Java異常分類剖析與自定義異常
- 第2章 自動配置Url前綴
- 06.參數校驗機制與LomBok工具集的使用
- 第1章 LomBok工具集的使用
- 第2章 參數校驗機制以及自定義校驗
- 07.項目分層設計與JPA技術
- 第1章 項目分層原則與層與層的松耦合原則
- 第2章 數據庫設計、實體關系與查詢方案探討
- 第3章 JPA的關聯關系與規則查詢
- 08.ORM的概念與思維
- 第1章 ORM的概念與思維
- 第2章 Banner等相關業務
- 第3章 再談數據庫設計技巧與VO層對象的技巧
- 09.JPA的多種查詢規則
- 第1章 DozerBeanMapper的使用
- 第2章 詳解SKU的規格設計
- 第3章 通用泛型Converter
- 10.令牌與權限
- 第1章 通用泛型類與java泛型的思考
- 常見問題
- 微服務
- demo
- PHP中Self、Static和parent的區別
- Swoole-Cli
- 為什么要使用現代化PHP框架?
- 公眾號
- 一鍵部署微信公眾號Markdown編輯器(支持適配和主題設計)
- Autodesigner 2.0發布
- Luya 一個現代化PHP開發框架
- PHPZip - 創建、讀取和管理 ZIP 文件的簡單庫
- 吊打Golang的PHP界天花板webman壓測對比
- 簡潔而強大的 YAML 解析庫
- 推薦一個革命性的PHP測試框架:Kahlan
- ServBay下一代Web開發環境
- 基于Websocket和Canvas實現多人協作實時共享白板
- Apipost預執行腳本如何調用外部PHP語言
- 認證和授權的安全令牌 Bearer Token
- Laradock PHP 的 Docker 完整本地開發環境
- 高效接口防抖策略,確保數據安全,避免重復提交的終極解決方案!
- TIOBE 6月榜單:PHP穩步前行,編程語言生態的微妙變化
- Aho-Corasick字符串匹配算法的實現
- Redis鍵空間通知 Keyspace Notification 事件訂閱
- ServBay如何啟用并運行Webman項目
- 使用mpdf實現導出pdf文件功能
- Medoo 輕量級PHP數據庫框架
- 在PHP中編寫和運行單元測試
- 9 PHP運行時基準性能測試
- QR碼生成器在PHP中的源代碼
- 使用Gogs極易搭建的自助Git服務
- Gitea
- webman如何記錄SQL到日志?
- Sentry PHP: 實時監測并處理PHP應用程序中的錯誤
- Swoole v6 Alpha 版本已發布
- Proxypin
- Rust實現的Redis內存數據庫發布
- PHP 8.4.0 Alpha 1 測試版本發布
- 121
- Golang + Vue 開發的開源輕量 Linux 服務器運維管理面板
- 內網穿透 FRP VS Tailscale
- 新一代開源代碼托管平臺Gitea
- 微服務系列
- Nacos云原生配置中心介紹與使用
- 輕量級的開源高性能事件庫libevent
- 國密算法
- 國密算法(商用密碼)
- GmSSL 支持國密SM2/SM3/SM4/SM9/SSL 密碼工具箱
- GmSSL PHP 使用
- 數據庫
- SQLite數據庫的Web管理工具
- 阿里巴巴MySQL數據庫強制規范
- PHP
- PHP安全測試秘密武器 PHPGGC
- 使用declare(strict_types=1)來獲得更健壯的PHP代碼
- PHP中的魔術常量
- OSS 直傳阿里騰訊示例
- PHP源碼編譯安裝APCu擴展實現數據緩存
- BI性能DuckDB數據管理系統
- 為什么別人可以是架構師!而我卻不是?
- 密碼還在用 MD5 加鹽?不如試試 password_hash
- Elasticsearch 在電商領域的應用與實踐
- Cron 定時任務入門
- 如何動態設置定時任務!而不是寫死在Linux Crontab
- Elasticsearch的四種查詢方式,你知道多少?
- Meilisearch vs Elasticsearch
- OpenSearch vs Elasticsearch
- Emlog 輕量級開源博客及建站系統
- 現代化PHP原生協程引擎 PRipple
- 使用Zephir編寫C擴展將PHP源代碼編譯加密
- 如何將PHP源代碼編譯加密,同時保證代碼能正常的運行
- 為什么選擇Zephir給PHP編寫動態擴展庫?
- 使用 PHP + XlsWriter實現百萬級數據導入導出
- Rust編寫PHP擴展
- 阿里云盤開放平臺對接進行文件同步
- 如何構建自己的PHP靜態可執行文件
- IM后端架構
- RESTful設計方法和規范
- PHP編譯器BPC 7.3 發布,成功編譯ThinkPHP8
- 高性能的配置管理擴展 Yaconf
- PHP實現雪花算法庫 Snowflake
- PHP官方現代化核心加密庫Sodium
- pie
- 現代化、精簡、非阻塞PHP標準庫PSL
- PHP泛型和集合
- 手把手教你正確使用 Composer包管理
- JWT雙令牌認證實現無感Token自動續期
- 最先進PHP大模型深度學習庫TransformersPHP
- PHP如何啟用 FFI 擴展
- PHP超集語言PXP
- 低延遲雙向實時事件通信 Socket.IO
- PHP OOP中的繼承和多態
- 強大的現代PHP高級調試工具Kint
- PHP基金會
- 基于webman+vue3高質量中后臺框架SaiAdmin
- 開源免費的定時任務管理系統:Gocron
- 簡單強大OCR工具EasyOCR在PHP中使用
- PHP代碼抽象語法樹工具PHP AST Viewer
- MySQL數據庫管理工具PHPMyAdmin
- Rust編寫的一款高性能多人代碼編輯器Zed
- 超高性能PHP框架Workerman v5.0.0-beta.8 發布
- 高并發系列
- 入門介紹及安裝
- Lua腳本開發 Hello World
- 執行流程與階段詳解
- Nginx Lua API 接口開發
- Lua模塊開發
- OpenResty 高性能的正式原因
- 記一次查找 lua-resty-mysql 庫 insert_id 的 bug
- 包管理工具OPM和LuaRocks使用
- 異步非阻塞HTTP客戶端庫 lua-resty-http
- Nginx 內置綁定變量
- Redis協程網絡庫 lua-resty-redis
- 動態HTML渲染庫 lua-testy-template
- 單獨的
- StackBlitz在線開發環境
- AI
- 基礎概念
- 12312
- 基礎鏡像的坑
- 利用phpy實現 PHP 編寫 Vision Transformer (ViT) 模型
- 語義化版本 2.0.0