OpenResty Edge Frequently Asked Questions

🔗 OpenResty Edge Installation FAQ

🔗 System Requirements and Architecture

🔗 What are the main components of OpenResty Edge and their respective roles?

OpenResty Edge mainly consists of three core components: Edge Admin (management console), Edge Log Server (log and metrics server), and Edge Node (gateway node). Additionally, there are two data storage components: Edge Admin Database and Edge Log Server Database.

🔗 What hardware configuration is required to install OpenResty Edge?

A production environment requires at least three machines, each installing Edge Admin + Admin DB, Log Server + Log Server DB, and Edge Node. For clusters with less than 10 nodes, it is recommended that Edge Admin and Log Server have at least 4 cores, 16GB RAM, and 200GB SSD. The configuration for Edge Node depends on the business volume, generally 1 core with 2GB RAM.

🔗 My network environment has firewall restrictions. Which ports and domains need to be opened?

You need to whitelist port 443 of openresty.com, openresty.org, pkg.openresty.com, and api.openresty.com. Specific ports also need to be opened between components: Edge Admin requires ports 443 and 12345, and Log Server requires ports 12346 and 8089.

🔗 Installation Process

🔗 How to obtain the installation package for OpenResty Edge?

You can obtain the configuration package (openresty-edge-VERSION.tar.gz) for online installation and the complete offline installation package (openresty-edge-bundle-VERSION.tar.gz) from the OpenResty download center (https://openresty.com/en/dashboard/downloads).

🔗 How to get the login account and password for the Edge Admin management interface after installation?

You can use the "Get Default Info" feature of the installer to obtain the default login information, or contact technical support to reset the password.

🔗 How to verify if each component is working properly after installation?

You can check the status of each service using the systemctl status command, such as sudo systemctl status oredge-admin. You can also check the log directories of each component, such as /usr/local/oredge-admin/logs, for any abnormal information.

🔗 Configuration and High Availability

🔗 How to improve the availability of Edge Admin and Log Server?

You can configure two Edge Admin services in dual-master mode or deploy multiple Log Server instances. Edge Admin requires modifying the clone_admin configuration in config.ini, and Edge Node needs to configure the host2 field under the admin section. Multiple Log Server instances need to be added to the configuration of both Edge Admin and Edge Node.

🔗 How to ensure data security? What are the data backup solutions?

It is recommended to regularly back up the database. You can refer to the Database Backup section in the documentation. You can also set up a database cluster to achieve automatic master-slave switching and improve database availability.

🔗 How to update the SSL certificate of Edge Admin after installation?

You can manually replace the /usr/local/oredge-admin/conf/ssl/ssl.crt and /usr/local/oredge-admin/conf/ssl/ssl.key files, or specify the certificate path using the -s and -k parameters during installation. Alternatively, you can use Edge Node to proxy the traffic of Edge Admin and issue SSL certificate for Edge Admin.

🔗 Troubleshooting

🔗 What to do if the "not yet approved" error appears after installing Edge Node?

This is a normal phenomenon, indicating that Edge Node has successfully connected to Edge Admin and needs to be approved in the Edge Admin management console to join. You can refer to the Gateway Cluster documentation for operation.

🔗 OpenResty Edge™ SDK Customer FAQ

🔗 Where to obtain the most critical authentication information (address, port, username, password) when using the SDK?

This information is consistent with the information you use to log in to the Edge Admin Web console. The parameters required for Edge2Client initialization are your backend access address and login credentials. If your Admin uses a non-standard HTTPS port, be sure to specify it clearly in the address.

🔗 My development environment uses a self-signed certificate, and the SDK reports an SSL error when connecting. How to handle it?

This is a very common scenario. You only need to execute client.set_ssl_verify(False) before calling client.login() to skip certificate verification. However, in a production environment, it is strongly recommended to configure a valid certificate issued by an authoritative CA to ensure security.

🔗 I called the API to modify the configuration, why didn't it take effect? What is the correct release process?

All configuration changes in the SDK are transactional and will not be automatically published. This is a safety design to prevent misoperations from affecting online services. The correct process is "Modify -> Publish -> Verify":

  1. Modify: Call interfaces such as new_rule(), put_app() to make changes.
  2. Publish: Call client.new_release() to create a new version of all pending changes and make it effective.
  3. Verify: (Optional but recommended) Call client.sync_status() to check if the configuration has been synchronized to all nodes.

🔗 What are the best practices for automating operations (such as batch updating rules, IP lists) using the SDK?

  1. Idempotency: Before performing a create operation, first query whether the target exists to avoid duplicate creation. When performing updates, ensure that the script can be run repeatedly.
  2. Robustness: Use try...except to catch exceptions in all API calls and record detailed logs.
  3. Performance considerations: For large-scale batch operations (such as updating thousands of IPs at once), it is recommended to process the data in batches and add a short delay (such as 1 second) between batches to avoid triggering the Admin's protection mechanism due to high request frequency.

🔗 How do I integrate the SDK into my CI/CD pipeline (such as Jenkins, GitLab CI) to achieve Configuration as Code?

This is the most valuable application scenario of the SDK. The usual approach is:

  1. Code Configuration: Store your Edge application configuration (such as upstreams, rules, etc.) in a specific format (such as YAML, JSON) in the code repository.
  2. Write a synchronization script: Develop a Python script that reads the coded configuration file and calls the SDK interface to apply the configuration to Edge Admin.
  3. Integrate into CI/CD: Add a stage in your CI/CD pipeline that automatically triggers the Python script to complete the configuration change and release it to Edge when the configuration code changes.
  4. Credential Management: Store the high-privilege password for logging into Edge Admin in the CI/CD system's secret management tool and pass it to the script securely to avoid plaintext storage.

🔗 OpenResty Edge Dynamic Metrics FAQ

🔗 What is the core value of the "Dynamic Metrics" feature? In what scenarios should I use it?

Its core value is to provide deep customized business and security insights that standard dashboards cannot satisfy. You should use it in the following scenarios:

  • Track specific business metrics: For example, count the number of requests from VIP users, the success rate of API calls for a newly launched event, the distribution of requests from different Android versions, etc.
  • Conduct fine-grained security analysis: For example, find the Top 10 IP addresses that attack a specific URI the most, or count the proportion of requests intercepted by WAF from a specific country.
  • Implement custom performance monitoring: For example, calculate the P99 response latency of a specific upstream service, rather than just the average.

🔗 Before writing a query, how do I know which data tables and fields are available? Is there a data dictionary?

This is the most critical first step. The data sources you can rely on are mainly the reqs (request logs) and waf_hits (WAF logs) virtual tables. To know the exactly available fields they contain (such as client_ip, status, uri, resp_header('Content-Type'), etc.), the most authoritative way is to consult the Dynamic Metrics section in the OpenResty Edge official documentation.

🔗 I want to count a business metric, such as "count the Top 10 users with the highest request volume based on the user_id field in JWT", is it possible?

Yes, this is exactly the strength of dynamic metrics. Assuming your user_id is in the request header named X-Jwt-Claim-User-Id, the query can be written as follows:

-- Assuming user_id is in the request header 'X-Jwt-Claim-User-Id'
SELECT ngx_var('http_x_jwt_claim_user_id') as user_id, count(*) as count
FROM reqs
WHERE ngx_var('http_x_jwt_claim_user_id') != ''
GROUP BY user_id
ORDER BY count DESC
LIMIT 10;

The key is to use the ngx_var() function to obtain custom request headers (with the http_ prefix) or other Nginx variables, thereby associating business logic with log data.

🔗 Where are dynamic metrics queries executed? Will they affect the performance of the online gateway?

This is a very important security question. Dynamic metrics queries are executed on the Edge Log Server, which processes log data collected from the gateway nodes in bypass mode. Therefore, no matter how complex your queries are, they will not affect the performance of the Edge Node (gateway node) that handles real-time business traffic. You can safely use this feature for complex data analysis.

🔗 OpenResty Edge Edgelang FAQ

🔗 In what scenarios should I use Edgelang instead of the standard page rules UI?

This is the most core decision issue. You should consider using Edgelang in scenarios where standard UI rules cannot meet the requirements, are complex, dynamic, or have extreme performance requirements.

  • Standard Rules UI: Suitable for common, static logic, such as "redirect to new-url when URI is /path". It is simple, intuitive, and ready to use.
  • Edgelang: Suitable for scenarios that require "programming" logic, such as:
    • Complex conditions: Need to make combined judgments based on multiple request headers, Cookies, client IP geographic location, etc.
    • Response processing: Need to dynamically modify the response body content (such as inserting JS scripts in HTML) or response headers.
    • Dynamic routing: Need to dynamically select upstream services based on specific request parameters (such as user ID, and area code).
    • Performance optimization: When you have hundreds of rules, the Edgelang compiler will optimize them into an efficient single code block, which usually performs better than the sequential execution of hundreds of independent page rules.

🔗 What is the most powerful application scenario of Edgelang? Can you give an example?

The most powerful aspect of Edgelang is its deep programming and control capabilities over requests and responses. The most typical "killer" application scenarios are A/B testing and staging releases.

Example: Implement staging release based on user ID Assume you want users with a user ID ending in "7" to access the new upstream service new-backend-upstream, while other users access the old version.

# Rule: staging Release
# When the cookie in the request contains userid, and userid ends with '7'
req-cookie("userid"), req-cookie("userid") suffix "7" =>
  set-upstream-name("new-backend-upstream");

This logic can also be implemented with standard UI rules, but it is more concise and efficient with Edgelang.

🔗 I have written a piece of Edgelang code, how do I deploy and execute it?

Edgelang code is not deployed independently but is executed as an action of a page rule. The process is as follows:

  1. Write code: Write your Edgelang rules in a code editor.
  2. Create a page rule: Create a new page rule under an application in Edge Admin.
  3. Set conditions: (Optional) Set trigger conditions for the requests you want to execute Edgelang, such as "URI path prefix is /api/".
  4. Select action: In the "action" section of the rule, select "Execute Edgelang" as the action.
  5. Paste code: Paste your written Edgelang code into the action input box.
  6. Save and publish: Save and publish this page rule.

After that, when a request matches the conditions you set, your embedded Edgelang code will be executed.

🔗 What is the execution order of Edgelang? How does it cooperate with other rules such as WAF and caching?

As part of the page rules, Edgelang's execution follows the Nginx processing phases and the priority of page rules. A simplified request processing flow is as follows:

  1. Page rules (including Edgelang or WAF): The request will enter the processing logic of the page rules. At this time, rules containing Edgelang or WAF will be executed according to their priority (which can be dragged and sorted in the UI) and trigger conditions.
  2. Caching: Edgelang can control subsequent behavior. For example, you can call the enable-proxy-cache() action in an Edgelang rule to decide whether to enable caching for a request.

🔗 How is the performance and security of Edgelang? What if I write problematic code?

  • Performance: Extremely high. The Edgelang compiler will deeply analyze and optimize your rules (even across multiple rules) to generate very efficient Lua code. Its performance is usually better than the combination of a large number of independent page rules.
  • Security:
    • Compile-time check: The Edgelang compiler will perform strict syntax and logic checks when you save the rules, and most low-level errors (such as syntax errors, and function name typos) will be discovered and prevented from being saved.
    • Sandbox environment: The execution of Edgelang is restricted to a secure sandbox environment, where it can only call the built-in functions and actions listed in the manual, and cannot execute arbitrary system commands or dangerous operations.
    • Testing: Although there is currently no independent "dry run" mode, the best practice is to first deploy and test your Edgelang rules on a non-production application or service to verify their logical correctness before applying them to the production environment.

🔗 OpenResty Edge 安装常见问题

🔗 系统要求与架构

🔗 OpenResty Edge 包含哪些主要组件?它们各自的作用是什么?

OpenResty Edge 主要包含三个核心组件:Edge Admin (管理控制台)、Edge Log Server(日志和指标服务器)和 Edge Node(网关节点)。此外还有两个数据存储组件:Edge Admin Database 和 Edge Log Server Database。

🔗 安装 OpenResty Edge 需要什么样的硬件配置?

正式环境至少需要三台机器,分别安装 Edge Admin + Admin DB、Log Server + Log Server DB 和 Edge Node。对于 10 个节点以内的集群,Edge Admin 和 Log Server 推荐至少 4 核 16G 内存 200G SSD,Edge Node 根据业务量而定,一般 1 核心配 2G 内存。

🔗 我的网络环境有防火墙限制,需要开放哪些端口和域名?

需要将 openresty.com 、openresty.org 、pkg.openresty.com 、api.openresty.com 的 443 端口加入白名单。各组件间也需要开放特定端口:Edge Admin 需要开放 443 和 12345 端口,Log Server 需要开放 12346 和 8089 端口。

🔗 安装过程

🔗 如何获取 OpenResty Edge 的安装包?

可以从 OpenResty 的下载中心 (https://openresty.com.cn/cn/dashboard/downloads) 获取在线安装包所需的配置包 (openresty-edge-VERSION.tar.gz) 和完整的离线安装包 (openresty-edge-bundle-VERSION.tar.gz) 。

🔗 安装完成后如何获取 Edge Admin 管理界面的登录账号和密码?

可以使用安装器的“Get Default Info”功能获取默认登录信息,或者联系技术支持重置密码。

🔗 安装完成后如何验证各组件是否正常工作?

可以通过 systemctl status 命令检查各服务状态,例如 sudo systemctl status oredge-admin,也可以查看各组件的日志目录,如 /usr/local/oredge-admin/logs 中是否有异常信息。

🔗 配置与高可用

🔗 如何提高 Edge Admin 和 Log Server 的可用性?

可以配置两份 Edge Admin 服务为双主模式,或部署多个 Log Server 实例。Edge Admin 需要修改 config.ini 中的 clone_admin 配置,Edge Node 需要配置 admin 段下的 host2 字段。Log Server 多实例需要在 Edge Admin 和 Edge Node 的配置中添加多个 endpoints。

🔗 如何保障数据安全?有哪些数据备份方案?

建议定期备份数据库,可以参考文档中的数据库备份章节。也可以搭建数据库集群,实现主从自动切换,提高数据库可用性。

🔗 安装后如何更新 Edge Admin 的 SSL 证书?

可以手动替换 /usr/local/oredge-admin/conf/ssl/ssl.crt/usr/local/oredge-admin/conf/ssl/ssl.key 文件,或者在安装时通过 -s-k 参数指定证书路径。 另外也可以使用 Edge Node 来代理 Edge Admin 的流量,为 Edge Admin 签发 SSL 证书。

🔗 故障排查

🔗 Edge Node 安装后显示“not yet approved”错误怎么办?

这是正常现象,表示 Edge Node 已成功连接 Edge Admin,需要在 Edge Admin 管理后台中批准该节点加入。可以参考网关集群文档进行操作。

🔗 OpenResty Edge™ SDK 客户常见问题

🔗 使用 SDK 时,最关键的认证信息(地址、端口、用户名、密码)从哪里获取

这些信息与您登录 Edge Admin Web 控制台的信息完全一致。Edge2Client 初始化所需的参数即是您后台的访问地址和登录凭证。如果您的 Admin 使用了非标准的 HTTPS 端口,请务必在地址中明确指定。

🔗 我的开发环境使用自签名证书,SDK 连接时报 SSL 错误,如何处理

这是非常常见的场景。您只需在调用 client.login() 前,执行 client.set_ssl_verify(False) 即可跳过证书验证。但在生产环境,强烈建议配置由权威 CA 签发的有效证书以确保安全。

🔗 我调用 API 修改了配置,为何没生效?正确的发布流程是怎样的

SDK 的所有配置变更都是事务性的,不会自动发布。这是一种安全设计,防止误操作影响线上服务。正确的流程是“修改 -> 发布 -> 验证”:

  1. 修改:调用 new_rule(), put_app() 等接口执行变更。
  2. 发布:调用 client.new_release() 将所有待定变更创建一个新版本并使其生效。
  3. 验证:(可选但推荐)调用 client.sync_status() 检查配置是否已同步到所有节点。

🔗 使用 SDK 进行自动化操作(如批量更新规则、IP 名单)的最佳实践是什么?

  1. 幂等性: 在执行创建操作前,先查询目标是否存在,避免重复创建。在执行更新时,确保脚本可重复运行。
  2. 健壮性:在所有 API 调用外层都使用 try...except 捕获异常,并记录详细日志。
  3. 性能考量:对于大规模批量操作(如一次更新上千个 IP) ,建议将数据分批处理,并在批次间加入短暂延时(如 1 秒),避免因请求频率过高而触发 Admin 的保护机制。

🔗 如何将 SDK 集成到我的 CI/CD 流水线(如 Jenkins, GitLab CI)中,实现配置即代码(Configuration as Code)?

这是 SDK 最有价值的应用场景。通常的做法是:

  1. 代码化配置:将您的 Edge 应用配置(如上游、规则等)用特定格式(如 YAML, JSON)存储在代码仓库中。
  2. 编写同步脚本:开发一个 Python 脚本,该脚本读取代码化的配置文件,并调用 SDK 接口,将配置应用到 Edge Admin 中。
  3. 集成到 CI/CD:在您的 CI/CD 流水线中增加一个阶段(Stage),当配置代码发生变更时,自动触发该 Python 脚本,完成对 Edge 的配置变更和发布。
  4. 凭证管理:将登录 Edge Admin 的高权限密码存放在 CI/CD 系统的密钥管理工具中,并通过安全的方式传递给脚本,避免明文存储。

🔗 OpenResty Edge 动态指标常见问题 (FAQ)

🔗 “动态指标”功能的核心价值是什么?什么场景下我应该使用它?

它的核心价值是提供标准仪表盘无法满足的、深度定制的业务和安全洞察力。当您遇到以下场景时,就应该使用它:

  • 追踪特定业务指标:例如,统计 VIP 用户的请求数、某个新上线活动的 API 调用成功率、不同安卓版本的请求分布等。
  • 进行精细化安全分析:例如,找出攻击某个特定 URI 最多的 Top 10 IP 地址,或统计被 WAF 拦截的请求中,来自某个特定国家的比例。
  • 实现自定义的性能监控:例如,计算某个上游服务的 P99 响应延迟,而非仅仅是平均值。

🔗 在写查询前,我如何知道都能用哪些数据表和字段?有数据字典吗?

这是最关键的第一步。您可以依赖的数据源主要是 reqs (请求日志)和 waf_hits (WAF 日志)这两个虚拟表。要知道它们包含哪些确切的可用字段(例如 client_ip, status, uri, resp_header('Content-Type') 等),最权威的方式是查阅 OpenResty Edge 官方文档中关于动态指标章节。

🔗 我想统计一个业务指标,比如“根据 JWT 里的 user_id 字段,统计请求量最大的 Top 10 用户”,能做到吗?

可以,这正是动态指标的强大之处。假设您的 user_id 在名为 X-Jwt-Claim-User-Id 的请求头中,查询可以这样写:

-- 假设user_id在请求头'X-Jwt-Claim-User-Id'中
SELECT ngx_var('http_x_jwt_claim_user_id') as user_id, count(*) as count
FROM reqs
WHERE ngx_var('http_x_jwt_claim_user_id') != ''
GROUP BY user_id
ORDER BY count DESC
LIMIT 10;

关键在于利用 ngx_var() 函数来获取自定义请求头(http_ 前缀)或其他 Nginx 变量,从而将业务逻辑与日志数据关联起来。

🔗 动态指标查询是在哪里执行的?会不会影响线上网关的性能?

这是一个非常重要的安全问题。动态指标的查询是在 Edge Log Server(日志服务器)上执行的,它处理的是从网关节点旁路采集的日志数据。因此,无论您的查询多复杂,都不会对处理实时业务流量的 Edge Node(网关节点)造成任何性能影响。您可以放心地使用这一功能进行复杂的数据分析。

🔗 OpenResty Edge Edgelang 常见问题

🔗 我应该在什么场景下使用 Edgelang ,而不是使用标准的页面规则 UI?

这是最核心的决策问题。您应该在遇到标准 UI 规则无法满足的、复杂的、动态的或对性能有极致要求的场景时,考虑使用 Edgelang。

  • 标准规则 UI: 适用于常见的、静态的逻辑,例如“当 URI 是 /path 时,跳转到 new-url”。它简单、直观、开箱即用。
  • Edgelang: 适用于需要“编程”逻辑的场景,例如:
    • 条件复杂:需要基于多个请求头、Cookie 、客户端 IP 地理位置等信息进行组合判断。
    • 响应处理:需要动态修改响应体内容(比如在 HTML 中插入 JS 脚本)或响应头。
    • 动态路由:需要根据请求的特定参数(如用户 ID、区域码)来动态选择上游服务。
    • 性能优化:当您有上百条规则时,Edgelang 编译器会将它们优化成高效的单个代码块,其性能通常优于上百条独立页面规则的顺序执行。

🔗 Edgelang 最强大的应用场景是什么?能给个例子吗?

Edgelang 最强大的地方在于其 对请求和响应的深度编程和控制能力。最典型的“杀手级”应用场景是 A/B 测试 和 灰度发布。

示例:基于用户 ID 实现灰度发布 假设您想让用户 ID 尾号为“7”的用户访问新版上游服务 new-backend-upstream,其他用户访问旧版。

# 规则:灰度发布
# 当请求的 cookie 中包含 userid,且 userid 以 '7' 结尾时
req-cookie("userid"), req-cookie("userid") suffix "7" =>
  set-upstream-name("new-backend-upstream");

这个逻辑用标准 UI 规则也可以实现,但用 Edgelang 就更加简洁和高效。

🔗 我写好了一段 Edgelang 代码,如何部署和执行它?

Edgelang 代码并不是独立部署的,而是作为页面规则的一个动作来执行。流程如下:

  1. 编写代码:在代码编辑器中编写您的 Edgelang 规则。
  2. 创建页面规则:在 Edge Admin 的某个应用下,创建一个新的页面规则。
  3. 设置条件:(可选)为您希望执行 Edgelang 的请求设置触发条件,例如 URI路径前缀是 /api/
  4. 选择动作:在规则的“动作”部分,选择“执行 Edgelang”这个动作。
  5. 粘贴代码:将您写好的 Edgelang 代码粘贴到动作的输入框中。
  6. 保存并发布:保存并发布这条页面规则。

之后,当有请求匹配您设置的条件时,您嵌入的 Edgelang 代码就会被执行。

🔗 Edgelang 的执行顺序是怎样的?它和 WAF、缓存等其他规则如何协作?

Edgelang 作为页面规则的一部分,其执行遵循 Nginx 的处理阶段(Phases)和页面规则的优先级。一个简化的请求处理流程如下:

  1. 页面规则(包括 Edgelang 或 WAF):请求将进入页面规则的处理逻辑。此时,包含 Edgelang 或 WAF 的规则会根据其优先级 (在 UI 上可以拖动排序)和触发条件被执行。
  2. 缓存:Edgelang 可以控制后续的行为。例如,您可以在 Edgelang 规则中调用 enable-proxy-cache() 动作来决定是否对某个请求启用缓存。

🔗 Edgelang 的性能和安全性如何?如果我写了有问题的代码怎么办?

  • 性能:极高。Edgelang 编译器会将您的规则(甚至是跨多条规则)进行深度分析和优化,生成非常高效的 Lua 代码。其性能通常优于大量独立页面规则的组合。
  • 安全性:
    • 编译时检查:Edgelang 编译器会在您保存规则时进行严格的语法和逻辑检查,大部分低级错误(如语法错误、函数名写错)会在此时被发现并阻止保存。
    • 沙箱环境:Edgelang 的执行被限制在一个安全的沙箱环境中,它只能调用手册中列出的内置函数和动作,无法执行任意系统命令或危险操作。
    • 测试:虽然目前没有独立的“空跑”模式,但最佳实践是在一个非生产的应用或服务上先行部署和测试您的 Edgelang 规则,验证其逻辑正确性后,再应用到生产环境。

🔗 OpenResty Edge 安裝常見問題

🔗 系統要求與架構

🔗 OpenResty Edge 包含哪些主要元件?它們各自的作用是甚麼?

OpenResty Edge 主要包含三個核心元件:Edge Admin (管理控制檯)、Edge Log Server(日誌和指標伺服器)和 Edge Node(閘道器節點)。此外還有兩個資料儲存元件:Edge Admin Database 和 Edge Log Server Database。

🔗 安裝 OpenResty Edge 需要甚麼樣的硬體配置?

正式環境至少需要三臺機器,分別安裝 Edge Admin + Admin DB、Log Server + Log Server DB 和 Edge Node。對於 10 個節點以內的叢集,Edge Admin 和 Log Server 推薦至少 4 核 16G 記憶體 200G SSD,Edge Node 根據業務量而定,一般 1 核心配 2G 記憶體。

🔗 我的網路環境有防火牆限制,需要開放哪些埠和域名?

需要將 openresty.com 、openresty.org 、pkg.openresty.com 、api.openresty.com 的 443 埠加入白名單。各元件間也需要開放特定埠:Edge Admin 需要開放 443 和 12345 埠,Log Server 需要開放 12346 和 8089 埠。

🔗 安裝過程

🔗 如何獲取 OpenResty Edge 的安裝包?

可以從 OpenResty 的下載中心 (https://openresty.com.cn/cn/dashboard/downloads) 獲取線上安裝包所需的配置包 (openresty-edge-VERSION.tar.gz) 和完整的離線安裝包 (openresty-edge-bundle-VERSION.tar.gz) 。

🔗 安裝完成後如何獲取 Edge Admin 管理介面的登入賬號和密碼?

可以使用安裝器的“Get Default Info”功能獲取預設登入資訊,或者聯絡技術支援重置密碼。

🔗 安裝完成後如何驗證各元件是否正常工作?

可以透過 systemctl status 命令檢查各服務狀態,例如 sudo systemctl status oredge-admin,也可以檢視各元件的日誌目錄,如 /usr/local/oredge-admin/logs 中是否有異常資訊。

🔗 配置與高可用

🔗 如何提高 Edge Admin 和 Log Server 的可用性?

可以配置兩份 Edge Admin 服務為雙主模式,或部署多個 Log Server 例項。Edge Admin 需要修改 config.ini 中的 clone_admin 配置,Edge Node 需要配置 admin 段下的 host2 欄位。Log Server 多例項需要在 Edge Admin 和 Edge Node 的配置中新增多個 endpoints。

🔗 如何保障資料安全?有哪些資料備份方案?

建議定期備份資料庫,可以參考文件中的資料庫備份章節。也可以搭建資料庫叢集,實現主從自動切換,提高資料庫可用性。

🔗 安裝後如何更新 Edge Admin 的 SSL 證書?

可以手動替換 /usr/local/oredge-admin/conf/ssl/ssl.crt/usr/local/oredge-admin/conf/ssl/ssl.key 檔案,或者在安裝時透過 -s-k 引數指定證書路徑。 另外也可以使用 Edge Node 來代理 Edge Admin 的流量,為 Edge Admin 簽發 SSL 證書。

🔗 故障排查

🔗 Edge Node 安裝後顯示“not yet approved”錯誤怎麼辦?

這是正常現象,表示 Edge Node 已成功連線 Edge Admin,需要在 Edge Admin 管理後臺中批准該節點加入。可以參考閘道器叢集文件進行操作。

🔗 OpenResty Edge™ SDK 客戶常見問題

🔗 使用 SDK 時,最關鍵的認證資訊(地址、埠、使用者名稱、密碼)從哪裡獲取

這些資訊與您登入 Edge Admin Web 控制檯的資訊完全一致。Edge2Client 初始化所需的引數即是您後臺的訪問地址和登入憑證。如果您的 Admin 使用了非標準的 HTTPS 埠,請務必在地址中明確指定。

🔗 我的開發環境使用自簽名證書,SDK 連線時報 SSL 錯誤,如何處理

這是非常常見的場景。您只需在呼叫 client.login() 前,執行 client.set_ssl_verify(False) 即可跳過證書驗證。但在生產環境,強烈建議配置由權威 CA 簽發的有效證書以確保安全。

🔗 我呼叫 API 修改了配置,為何沒生效?正確的釋出流程是怎樣的

SDK 的所有配置變更都是事務性的,不會自動釋出。這是一種安全設計,防止誤操作影響線上服務。正確的流程是“修改 -> 釋出 -> 驗證”:

  1. 修改:呼叫 new_rule(), put_app() 等介面執行變更。
  2. 釋出:呼叫 client.new_release() 將所有待定變更建立一個新版本並使其生效。
  3. 驗證:(可選但推薦)呼叫 client.sync_status() 檢查配置是否已同步到所有節點。

🔗 使用 SDK 進行自動化操作(如批次更新規則、IP 名單)的最佳實踐是甚麼?

  1. 冪等性: 在執行建立操作前,先查詢目標是否存在,避免重複建立。在執行更新時,確保指令碼可重複執行。
  2. 健壯性:在所有 API 呼叫外層都使用 try...except 捕獲異常,並記錄詳細日誌。
  3. 效能考量:對於大規模批次操作(如一次更新上千個 IP) ,建議將資料分批處理,並在批次間加入短暫延時(如 1 秒),避免因請求頻率過高而觸發 Admin 的保護機制。

🔗 如何將 SDK 整合到我的 CI/CD 流水線(如 Jenkins, GitLab CI)中,實現配置即程式碼(Configuration as Code)?

這是 SDK 最有價值的應用場景。通常的做法是:

  1. 程式碼化配置:將您的 Edge 應用配置(如上游、規則等)用特定格式(如 YAML, JSON)儲存在程式碼倉庫中。
  2. 編寫同步指令碼:開發一個 Python 指令碼,該指令碼讀取程式碼化的配置檔案,並呼叫 SDK 介面,將配置應用到 Edge Admin 中。
  3. 整合到 CI/CD:在您的 CI/CD 流水線中增加一個階段(Stage),當配置程式碼發生變更時,自動觸發該 Python 指令碼,完成對 Edge 的配置變更和釋出。
  4. 憑證管理:將登入 Edge Admin 的高許可權密碼存放在 CI/CD 系統的金鑰管理工具中,並透過安全的方式傳遞給指令碼,避免明文儲存。

🔗 OpenResty Edge 動態指標常見問題 (FAQ)

🔗 “動態指標”功能的核心價值是甚麼?甚麼場景下我應該使用它?

它的核心價值是提供標準儀表盤無法滿足的、深度定製的業務和安全洞察力。當您遇到以下場景時,就應該使用它:

  • 追蹤特定業務指標:例如,統計 VIP 使用者的請求數、某個新上線活動的 API 呼叫成功率、不同安卓版本的請求分佈等。
  • 進行精細化安全分析:例如,找出攻擊某個特定 URI 最多的 Top 10 IP 地址,或統計被 WAF 攔截的請求中,來自某個特定國家的比例。
  • 實現自定義的效能監控:例如,計算某個上游服務的 P99 響應延遲,而非僅僅是平均值。

🔗 在寫查詢前,我如何知道都能用哪些資料表和欄位?有資料字典嗎?

這是最關鍵的第一步。您可以依賴的資料來源主要是 reqs (請求日誌)和 waf_hits (WAF 日誌)這兩個虛擬表。要知道它們包含哪些確切的可用欄位(例如 client_ip, status, uri, resp_header('Content-Type') 等),最權威的方式是查閱 OpenResty Edge 官方文件中關於動態指標章節。

🔗 我想統計一個業務指標,比如“根據 JWT 裡的 user_id 欄位,統計請求量最大的 Top 10 使用者”,能做到嗎?

可以,這正是動態指標的強大之處。假設您的 user_id 在名為 X-Jwt-Claim-User-Id 的請求頭中,查詢可以這樣寫:

-- 假設user_id在請求頭'X-Jwt-Claim-User-Id'中
SELECT ngx_var('http_x_jwt_claim_user_id') as user_id, count(*) as count
FROM reqs
WHERE ngx_var('http_x_jwt_claim_user_id') != ''
GROUP BY user_id
ORDER BY count DESC
LIMIT 10;

關鍵在於利用 ngx_var() 函式來獲取自定義請求頭(http_ 字首)或其他 Nginx 變數,從而將業務邏輯與日誌資料關聯起來。

🔗 動態指標查詢是在哪裡執行的?會不會影響線上閘道器的效能?

這是一個非常重要的安全問題。動態指標的查詢是在 Edge Log Server(日誌伺服器)上執行的,它處理的是從閘道器節點旁路採集的日誌資料。因此,無論您的查詢多複雜,都不會對處理實時業務流量的 Edge Node(閘道器節點)造成任何效能影響。您可以放心地使用這一功能進行復雜的資料分析。

🔗 OpenResty Edge Edgelang 常見問題

🔗 我應該在甚麼場景下使用 Edgelang ,而不是使用標準的頁面規則 UI?

這是最核心的決策問題。您應該在遇到標準 UI 規則無法滿足的、複雜的、動態的或對效能有極致要求的場景時,考慮使用 Edgelang。

  • 標準規則 UI: 適用於常見的、靜態的邏輯,例如“當 URI 是 /path 時,跳轉到 new-url”。它簡單、直觀、開箱即用。
  • Edgelang: 適用於需要“程式設計”邏輯的場景,例如:
    • 條件複雜:需要基於多個請求頭、Cookie 、客戶端 IP 地理位置等資訊進行組合判斷。
    • 響應處理:需要動態修改響應體內容(比如在 HTML 中插入 JS 指令碼)或響應頭。
    • 動態路由:需要根據請求的特定引數(如使用者 ID、區域碼)來動態選擇上游服務。
    • 效能最佳化:當您有上百條規則時,Edgelang 編譯器會將它們最佳化成高效的單個程式碼塊,其效能通常優於上百條獨立頁面規則的順序執行。

🔗 Edgelang 最強大的應用場景是甚麼?能給個例子嗎?

Edgelang 最強大的地方在於其 對請求和響應的深度程式設計和控制能力。最典型的“殺手級”應用場景是 A/B 測試 和 灰度釋出。

示例:基於使用者 ID 實現灰度釋出 假設您想讓使用者 ID 尾號為“7”的使用者訪問新版上游服務 new-backend-upstream,其他使用者訪問舊版。

# 規則:灰度釋出
# 當請求的 cookie 中包含 userid,且 userid 以 '7' 結尾時
req-cookie("userid"), req-cookie("userid") suffix "7" =>
  set-upstream-name("new-backend-upstream");

這個邏輯用標準 UI 規則也可以實現,但用 Edgelang 就更加簡潔和高效。

🔗 我寫好了一段 Edgelang 程式碼,如何部署和執行它?

Edgelang 程式碼並不是獨立部署的,而是作為頁面規則的一個動作來執行。流程如下:

  1. 編寫程式碼:在程式碼編輯器中編寫您的 Edgelang 規則。
  2. 建立頁面規則:在 Edge Admin 的某個應用下,建立一個新的頁面規則。
  3. 設定條件:(可選)為您希望執行 Edgelang 的請求設定觸發條件,例如 URI路徑字首是 /api/
  4. 選擇動作:在規則的“動作”部分,選擇“執行 Edgelang”這個動作。
  5. 貼上程式碼:將您寫好的 Edgelang 程式碼貼上到動作的輸入框中。
  6. 儲存併發布:儲存併發布這條頁面規則。

之後,當有請求匹配您設定的條件時,您嵌入的 Edgelang 程式碼就會被執行。

🔗 Edgelang 的執行順序是怎樣的?它和 WAF、快取等其他規則如何協作?

Edgelang 作為頁面規則的一部分,其執行遵循 Nginx 的處理階段(Phases)和頁面規則的優先順序。一個簡化的請求處理流程如下:

  1. 頁面規則(包括 Edgelang 或 WAF):請求將進入頁面規則的處理邏輯。此時,包含 Edgelang 或 WAF 的規則會根據其優先順序 (在 UI 上可以拖動排序)和觸發條件被執行。
  2. 快取:Edgelang 可以控制後續的行為。例如,您可以在 Edgelang 規則中呼叫 enable-proxy-cache() 動作來決定是否對某個請求啟用快取。

🔗 Edgelang 的效能和安全性如何?如果我寫了有問題的程式碼怎麼辦?

  • 效能:極高。Edgelang 編譯器會將您的規則(甚至是跨多條規則)進行深度分析和最佳化,生成非常高效的 Lua 程式碼。其效能通常優於大量獨立頁面規則的組合。
  • 安全性:
    • 編譯時檢查:Edgelang 編譯器會在您儲存規則時進行嚴格的語法和邏輯檢查,大部分低階錯誤(如語法錯誤、函式名寫錯)會在此時被發現並阻止儲存。
    • 沙箱環境:Edgelang 的執行被限制在一個安全的沙箱環境中,它只能呼叫手冊中列出的內建函式和動作,無法執行任意系統命令或危險操作。
    • 測試:雖然目前沒有獨立的“空跑”模式,但最佳實踐是在一個非生產的應用或服務上先行部署和測試您的 Edgelang 規則,驗證其邏輯正確性後,再應用到生產環境。