简体   繁体   中英

Where to find in server whether the request was made to DNS of website or the Server IP on the port

I have a website running on a centos 7 server and the nginx is used to serve the website.

My question is how can I identify in my server that whether the Domain Name of my website was hit or was the request made directly to my linux server's Public IP on the nginx port.

Thanks.

The default combined logfile format does not show the http_host header, which is probably what you need. You can define a custom logfile format (in your http block), and reference it from either the http block or specific server blocks. For example:

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;
    ...
}

The above is based on the default configuration with $http_host added. See this document for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM