【问题标题】:nginx redirection to another servernginx重定向到另一台服务器
【发布时间】:2019-02-23 05:38:12
【问题描述】:

我编译了 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;
}

【问题讨论】:

  • 所以你想将所有http重定向到https?
  • 是的,然后转到另一个 DNS。

标签: nginx nginx-location nginx-config


【解决方案1】:

你应该这样做

http {
  log_format custom '$request_body';

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

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

【讨论】:

  • return 是客户端重定向,在我的情况下,它无法重定向到第二个 DNS 并等待它响应。但是,当我使用 proxy_pass 重定向到第二个 DNS 时,它起作用了。它记录流量包络。现在,我想要记录标题和时间戳。你知道我的配置中缺少什么吗?
  • 你想记录 header,你想记录 header 中的所有内容吗? 时间戳,何时发出请求?
  • 我想同时记录标题和正文。
  • @Kedamang 是的,在标题中记录所有内容。如果它更容易记录的话,如果它默认记录的话。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-23
  • 1970-01-01
  • 2013-05-27
  • 1970-01-01
  • 2018-01-20
  • 2012-11-22
  • 1970-01-01
相关资源
最近更新 更多