此处不允许使用 Nginx“log_format”指令

问题描述 投票:0回答:2

我收到错误

/etc/nginx/conf.d/default.conf 中不允许使用“log_format”指令

nginx.conf

server {
   ---
    --
        log_format  custom  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
         access_log  /var/log/nginx/access.log custom if=$logme;

}

缺少什么?

nginx nginx-config
2个回答
0
投票

了解

Context:    http
文档的含义

events {
    # ...
}

http {
    upstream name {
       # ...
    }

    # HERE
    log_format custom  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    server {
       # ...
    }
}

-1
投票

您应该在

http
下指定
server
,这样它看起来应该像:

server {

  http {
    # your server configurations
  }
  
  # The rest configurations
   log_format  custom  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
   access_log  /var/log/nginx/access.log custom if=$logme;
}
© www.soinside.com 2019 - 2024. All rights reserved.