发布于 3年前

nginx: [emerg] "log_format" directive is not allowed here

配置Nginx,想在server内部配置log_format,报错:

nginx: [emerg] "log_format" directive is not allowed here in /etc/nginx/conf.d/default.conf:41

配置如下:

server {
        log_format mylog '$remote_addr - $remote_user [$time_local] $request'
                  '$status $body_bytes_sent $http_referer '
               '$http_user_agent $http_x_forwarded_for';
        listen       80;
        server_name example.com www.example.com *.demo.example.com;
        index index.html index.htm index.php;
        root  /mnt/web/example/wwwroot;
        access_log  /mnt/web/example/log/access.log mylog ;
        error_log  /mnt/web/example/log/error.log;
}

原因是log_format需要在server外部定义。

©2020 edoou.com   京ICP备16001874号-3