目录
access_log
log_format
首页 数据库 mysql教程 nginx: [warn] the "log_format" directive may be used only

nginx: [warn] the "log_format" directive may be used only

Jun 07, 2016 pm 03:31 PM
format log nginx the warn

运行nginx的时候老是报错: nginx:[warn]the"log_format"directivemaybeusedonlyon"http"levelinxxx/nginx.conf:95 虽然只是warning但是仍然影响心情,于是决定仔细看看它的结构。 example: log_formatgzip'$remote_addr - $remote_user [$time_local] ''"$

运行nginx的时候老是报错:

nginx: [warn] the "log_format" directive may be used only on "http" level in xxx/nginx.conf:95

虽然只是warning但是仍然影响心情,于是决定仔细看看它的结构。

 

example:

   log_format  gzip'$remote_addr - $remote_user [$time_local]  ''"$request" $status $bytes_sent ''"$http_referer" "$http_user_agent" "$gzip_ratio"';
 
  access_log  /spool/logs/nginx-access.log    gzip  buffer=32k;
登录后复制

access_log

Syntax: access_log path [ format [ buffer = size ]]

access_log off

Default: logs/access.log combined

Context: http

server
location
if in location
limit_except

Reference: access_log


The access_log directive sets the path, format and buffer size for the access log file. Using "off" as the only parameter clears all access_log directives for the current level. If the format is not indicated, it defaults to "combined". The size of buffer must not exceed the size of the atomic record for writing into the disk file. This size is not limited for FreeBSD 3.0-6.0.

The log file path can contain variables (version >=0.7.4) but such logs have some limitations:

  • worker user must have permission to create files in;

  • buffering does not work;

  • for each log entry, the file is opened and immediately closed after writing the record. However, descriptors of frequently used files may be stored in open_log_file_cache . Regarding log rotation, it must be kept in mind that over time (which is set by the parameter valid of directive open_log_file_cache), logging can be still continue to the old file.

Nginx supports powerful access log separation per location. Accesses can also be output to more than one log at the same time. For more details, see the Multiple access_log directives in different contexts thread on the mailing list.

log_format

Syntax: log_format name string ...

Default: combined "..."

Context: http

Reference: log_format


The log_format directive describes the format of a log entry. You can use general variables in the format, as well as variables which exist only at the moment of writing into the log:

  • $body_bytes_sent, the number of bytes, transmitted to client minus the response headers. This variable is compatible with the %B parameter of Apache's mod_log_config (this was called $apache_bytes_sent, before version 0.3.10)

  • $bytes_sent, the number of bytes transmitted to client

  • $connection, the number of connection

  • $msec, the current time at the moment of writing the log entry (microsecond accuracy)

  • $pipe, "p" if request was pipelined

  • $request_length, the length of the body of the request

  • $request_time, the time it took nginx to work on the request, in seconds with millisecond precision (just seconds for versions older than 0.5.19)

  • $status, status of answer

  • $time_iso8601, time in ISO 8601 format, e. g. 2011-03-21T18:52:25+03:00 (added in 0.9.6)

  • $time_local, local time into common log format.

The headers, transmitted to client, begin from the prefix "sent_http_", for example, $sent_http_content_range.

Note that variables produced by other modules can also be logged. For example you can log upstream response headers with the prefix "upstream_http_", see upstream .

There is a predefined log format called "combined":

  log_format combined '$remote_addr - $remote_user [$time_local]  ''"$request" $status $body_bytes_sent ''"$http_referer" "$http_user_agent"';
登录后复制

 

 

 参考文档:http://wiki.nginx.org/NginxHttpLogModule#open_log_file_cache 

 

正确的解决方法是:

将/usr/local/nginx/conf/nginx.conf 里server段里的下面代码移出放到该server段的前面即可。


log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';


如果有其的虚拟主机开启了日志,也按上面的要求移出server段放在server段的前面即可。

再/usr/local/nginx/sbin/nginx -t 测试一下,没有warn警告信息了。

 

人家nginx也提示了么,要放到 http 层,而不是server层里哦。

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

tomcat服务器怎么让外网访问 tomcat服务器怎么让外网访问 Apr 21, 2024 am 07:22 AM

要让 Tomcat 服务器对外网访问,需要:修改 Tomcat 配置文件,允许外部连接。添加防火墙规则,允许访问 Tomcat 服务器端口。创建 DNS 记录,将域名指向 Tomcat 服务器公有 IP。可选:使用反向代理提升安全性和性能。可选:设置 HTTPS 以提高安全性。

thinkphp怎么运行 thinkphp怎么运行 Apr 09, 2024 pm 05:39 PM

ThinkPHP Framework 的本地运行步骤:下载并解压 ThinkPHP Framework 到本地目录。创建虚拟主机(可选),指向 ThinkPHP 根目录。配置数据库连接参数。启动 Web 服务器。初始化 ThinkPHP 应用程序。访问 ThinkPHP 应用程序 URL 运行。

Welcome to nginx!怎么解决? Welcome to nginx!怎么解决? Apr 17, 2024 am 05:12 AM

要解决 "Welcome to nginx!" 错误,需要检查虚拟主机配置,启用虚拟主机,重新加载 Nginx,如果无法找到虚拟主机配置文件,则创建默认页面并重新加载 Nginx,这样错误消息将消失,网站将正常显示。

docker容器之间如何通信 docker容器之间如何通信 Apr 07, 2024 pm 06:24 PM

Docker 环境中容器通信有五种方法:共享网络、Docker Compose、网络代理、共享卷、消息队列。根据隔离性和安全性需求,选择最合适的通信方法,例如利用 Docker Compose 简化连接或使用网络代理提高隔离性。

nodejs项目怎么部署到服务器 nodejs项目怎么部署到服务器 Apr 21, 2024 am 04:40 AM

Node.js 项目的服务器部署步骤:准备部署环境:获取服务器访问权限、安装 Node.js、设置 Git 存储库。构建应用程序:使用 npm run build 生成可部署代码和依赖项。上传代码到服务器:通过 Git 或文件传输协议。安装依赖项:SSH 登录服务器并使用 npm install 安装应用程序依赖项。启动应用程序:使用 node index.js 等命令启动应用程序,或使用 pm2 等进程管理器。配置反向代理(可选):使用 Nginx 或 Apache 等反向代理路由流量到应用程

html文件怎么生成网址 html文件怎么生成网址 Apr 21, 2024 pm 12:57 PM

要将 HTML 文件转换为网址,需要使用网络服务器,包括以下步骤:获取网络服务器。设置网络服务器。上传 HTML 文件。创建域名。路由请求。

dockerfile中最常见的指令是什么 dockerfile中最常见的指令是什么 Apr 07, 2024 pm 07:21 PM

Dockerfile 中最常用的指令有:FROM:创建新镜像或派生新镜像RUN:执行命令(安装软件、配置系统)COPY:复制本地文件到镜像ADD:类似 COPY,可自动解压缩 tar 存档或获取 URL 文件CMD:指定容器启动时的命令EXPOSE:声明容器监听端口(但不公开)ENV:设置环境变量VOLUME:挂载主机目录或匿名卷WORKDIR:设置容器中的工作目录ENTRYPOINT:指定容器启动时要执行的可执行文件(类似 CMD,但不可覆盖)

nodejs可以外网访问么 nodejs可以外网访问么 Apr 21, 2024 am 04:43 AM

是的,Node.js 可以外网访问。您可以使用以下方法:使用 Cloud Functions 部署函数并公开访问。使用 Express 框架创建路由并定义端点。使用 Nginx 反向代理请求到 Node.js 应用程序。使用 Docker 容器运行 Node.js 应用程序并通过端口映射公开。

See all articles