nginx配置日志格式报错 log_format" directive is not allowed here

什么情况下 会遇到这个情况 你想解决什么问题?

Nginx的基本配置log_format 写法 配置文件内容如下

log_format soshash.log.format '$remote_addr - $remote_user [$time_local] $request'
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';

server {
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 example.log.format;
error_log /mnt/web/example/log/error.log;
}a

其实 看完这一段 前面的问题 自然就解决了

因为出现log_format" directive is not allowed here 很明显 不允许放到这里 就只能说 写的位置不对

因为 最新版本的nginx(1.12.0)需要将log_format 放置到server段外部,否则会报一个类似:nginx: [emerg] "log_format" directive is not allowed here in的错误

ok 本文结束

参考资料 https://my.oschina.net/u/2366984/blog/900094

参考资料

Nginx 挂CDN 如何获取真实访客IP地址,对付cloudflare 及任意CDN通用办法,独家绝密资料

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。