You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx报错‘log_format directive is not allowed here’,求助排查缺失配置

Nginx配置错误:log_format指令位置非法
  • 错误原因:log_format是Nginx的http块级别指令,不允许在server块内部定义,你把它放在了server块里,所以触发了这个报错。
  • 修正方法:将log_format custom的定义代码移动到http块下(与所有server块同级的位置),server块内仅保留access_log的配置。

修正后的配置示例:

http {
    # 自定义日志格式放在http块级别
    log_format  custom  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    server {
        # 其他server相关配置...
        access_log  /var/log/nginx/access.log custom if=$logme;
    }
}

内容的提问来源于stack exchange,提问作者marcg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 07:22:05