Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从nginx docker映像记录http请求正文?_Http_Docker_Nginx_Logging - Fatal编程技术网

如何从nginx docker映像记录http请求正文?

如何从nginx docker映像记录http请求正文?,http,docker,nginx,logging,Http,Docker,Nginx,Logging,我和nginx有一张docker的照片 我想记录传入的请求 我的docker撰写文件: nginx: container_name: my-nginx image: nginx ports: - "80:80" - "443:443" volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf - ./access.log:/var/log/nginx/test.com.access.log 我的nginx配置: serve

我和nginx有一张docker的照片

我想记录传入的请求

我的docker撰写文件:

nginx:
  container_name: my-nginx
image: nginx
ports:
  - "80:80"
  - "443:443"
volumes:
  - ./nginx.conf:/etc/nginx/conf.d/default.conf
  - ./access.log:/var/log/nginx/test.com.access.log
我的nginx配置:

server {
 listen 80;
 listen 443 default_server ssl;
 access_log /var/log/nginx/test.com.access.log;

 location / {
  proxy_pass http://myapp:8080;
  proxy_buffering off;
 }
}
当我尝试用以下配置替换
access\u log
指令时:

log_format testlog '$remote_addr - $remote_user [$time_local] '
                   '"$request" $status $bytes_sent '
                   '"$http_referer" "$http_user_agent" "$request_body"';
access_log /var/log/nginx/test.com.access.log testlog;
我得到:

nginx-reverse-proxy | 2018/04/06 11:50:00 [emerg] 1#1: "log_format" directive is not allowed here in /etc/nginx/conf.d/default.conf:10
nginx-reverse-proxy | nginx: [emerg] "log_format" directive is not allowed here in /etc/nginx/conf.d/default.conf:10

这似乎是一个复制品

该消息表示您在某个不允许的地方有一个
http
指令,即

http {
    ...
}
您可能希望使用
服务器
块,即

server {
    listen 80 default_server;
    server_name test.com;
    root /var/www/test/;
    access_log /var/log/nginx/test.com.access.log;
}

这似乎是一个复制品

该消息表示您在某个不允许的地方有一个
http
指令,即

http {
    ...
}
您可能希望使用
服务器
块,即

server {
    listen 80 default_server;
    server_name test.com;
    root /var/www/test/;
    access_log /var/log/nginx/test.com.access.log;
}

将log_格式放在
server{}
块之外,因为不是每个指令都可以到达任何地方。简单地说:

log_format testlog '$remote_addr - $remote_user [$time_local] '
               '"$request" $status $bytes_sent '
               '"$http_referer" "$http_user_agent" "$request_body"';

server {
 listen 80;
 listen 443 default_server ssl;
 access_log /var/log/nginx/test.com.access.log;

 location / {
  proxy_pass http://myapp:8080;
  proxy_buffering off;
 }
}
此处记录:“上下文:http”


http
context是顶层块,它包含
server
块(通常您看不到它,因为它位于包含.conf的另一个文件中)

将日志格式放在
server{}
块之外,因为不是每个指令都可以到达任何地方。简单地说:

log_format testlog '$remote_addr - $remote_user [$time_local] '
               '"$request" $status $bytes_sent '
               '"$http_referer" "$http_user_agent" "$request_body"';

server {
 listen 80;
 listen 443 default_server ssl;
 access_log /var/log/nginx/test.com.access.log;

 location / {
  proxy_pass http://myapp:8080;
  proxy_buffering off;
 }
}
此处记录:“上下文:http”


http
上下文是顶层块,它包含
服务器
块(通常您看不到它,因为它位于包含.conf的另一个文件中)

但是如何在您提供的配置中记录http正文?如果需要记录请求正文,您可以签出。您可以发布整个nginx配置文件吗?也许在确定的情况下,我的文件您提供的调试日志与要点不匹配,请更新您的问题,使其符合。。。如果我没有正确的调试信息,我无法帮助您,但是如何在您提供的配置中记录http正文?如果您需要记录请求正文,您可以签出。您可以发布整个nginx配置文件吗?也许在确定的情况下,我的文件您提供的调试日志与要点不匹配,请更新您的问题,使其符合。。。如果我没有正确的调试信息,我无法帮助您,您不应该在同一服务器块中有HTTP和HTTPS的侦听器,而是为HTTPS创建一个单独的侦听器,包括所需的SSL密钥。您不应该在同一服务器块中有HTTP和HTTPS的侦听器,而是为HTTPS创建一个单独的HTTPS,包括所需的SSL密钥。