【问题标题】:Where to find in server whether the request was made to DNS of website or the Server IP on the port在服务器中的哪里可以找到请求是向网站的 DNS 还是端口上的服务器 IP 发出的
【发布时间】:2016-08-06 04:58:27
【问题描述】:

我有一个网站在 centos 7 服务器上运行,nginx 用于为网站提供服务。

我的问题是如何在我的服务器中识别我的网站的域名是否被点击或者是直接向我的 linux 服务器的 nginx 端口上的公共 IP 发出的请求。

谢谢。

【问题讨论】:

  • DNS 服务器在连接到网络服务器之前总是将名称转换为 IP 地址。但是网络服务器至少可以在 apache 上执行反向 DNS 查找以获取主机名。这通常被关闭以提高性能。

标签: linux nginx dns


【解决方案1】:

默认的combined 日志文件格式不显示http_host 标头,这可能是您需要的。您可以定义自定义日志文件格式(在您的 http 块中),并从 http 块或特定的 server 块中引用它。例如:

http {
    log_format custom '$remote_addr - $remote_user [$time_local] '
                      '"$http_host" '
                      '"$request" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent"';

    access_log /var/log/nginx-access.log custom;
    ...
}

以上基于默认配置添加$http_host。详情请见this document。

【讨论】:

    猜你喜欢
    • 2015-01-25
    • 2011-06-15
    • 2010-12-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2016-02-27
    相关资源
    最近更新 更多