nginx重定向到另一台服务器

时间:2018-09-19 06:07:14

标签: nginx nginx-location nginx-config

我编译了nginx'echo-nginx-module'模块以记录请求正文。 我的目标是记录并反向代理将所有到达nginx的流量转发到另一个DNS。 我正在使用proxy_pass将流量重定向到第二个DNS,它成功开始记录流量主体。 但是,缺少的是我还需要记录流量标头和时间戳。 我已经将以下几行添加到proxy_pass配置文件中,它似乎没有记录标题。我想念什么?

location / {

    # the below four lines do not log header and body
    echo "headers are:"
    echo $echo_client_request_headers;
    echo_read_request_body;
    echo $request_body;

    # this works and logs traffic envelope
    proxy_pass https://offexserver-test-internal.leapaws.com.au;
    root   html;
    index  index.html index.htm;
}

1 个答案:

答案 0 :(得分:0)

您应该做这样的事情

http {
  log_format custom '$request_body';

  server {    
    server_name default_server;
    listen 80;
    location / {
      echo_read_request_body;
    }      
  }
}

您无法记录所有标头,唯一可以做的就是单独指定要记录的标头。否则您将不得不使用其他module来配置标头。

相关问题