跳转至

error-log-write: 配置中的条件错误日志条目

安装

您可以在任何基于 RHEL 的发行版中安装此模块,包括但不限于:

  • RedHat Enterprise Linux 7, 8, 9 和 10
  • CentOS 7, 8, 9
  • AlmaLinux 8, 9
  • Rocky Linux 8, 9
  • Amazon Linux 2 和 Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-error-log-write
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-error-log-write

通过在 /etc/nginx/nginx.conf 顶部添加以下内容来启用模块:

load_module modules/ngx_http_error_log_write_module.so;

本文档描述了 nginx-module-error-log-write v0.1.0,于 2026 年 1 月 6 日发布。


error_log_write level=info message="main test log";

server {
    listen 127.0.0.1:80;
    server_name localhost;

    error_log_write  message="server test log" if=$arg_test;

    location / {
        error_log_write level=warn message="auth required" if!=$http_authorization;
        auth_baisc "auth required";
        auth_basic_user_file conf/htpasswd;
        proxy_pass http://example.upstream.com;
    }
}

指令

error_log_write

语法: error_log_write [level=log_level] message=text [if=condition];

默认值: -

上下文: http, server, location

写入新的错误日志。所有错误日志条目无条件地从上一个配置级别继承。

GitHub

您可以在 nginx-module-error-log-write 的 GitHub 仓库 中找到此模块的其他配置提示和文档。