How to log virtual server name
Lucian D. Kafka
luci at Conexim.com.au
Tue Feb 28 02:27:58 UTC 2012
Thank you for that Francis.
Using your testing battery with different curl headers I was able to narrow down the issue.
Basically nginx logs correctly any virtual host name under the sun (specified or not under the server_name) - except one. This is exactly the same one it complains as having a conflict on startup.
If I take out this one server name of the server_name directive (ie. this name is not mentioned in any nginx config files), the complaining about conflict stops, but logging for this one host does not work - ie $host (and all other variants) are empty.
From: nginx-bounces at nginx.org [mailto:nginx-bounces at nginx.org] On Behalf Of Francis Daly
Sent: Tuesday, 28 February 2012 10:36 AM
To: nginx at nginx.org
Subject: Re: How to log virtual server name
On Mon, Feb 27, 2012 at 10:49:38PM +0000, Lucian D. Kafka wrote:
> The _problem_ is that Nginx does not behave as the documentation describes. Entering multiple server names in one server_name directive and using $http_host do not work.
The following "http" section of nginx.conf allows me to see content from two different directories, depending on the Host: header in the request; and includes the hostname used in the Host: header in the access_log file.
It behaves for me as the documentation describes.
What is the difference between this and the configuration file you are using?
log_format mine '$host $remote_addr - "$request" $status';
access_log logs/mine.log mine;
server_name one two;
listen 8000 default_server;
If I use $http_host instead of $host, I see whatever the client sent -- including the :port part.
Testing using commands like
curl -i http://localhost:8000/
curl -i -H 'Host: one' http://localhost:8000/
curl -i -H 'Host: two:66' http://localhost:8000/
curl -i -H 'Host: three' http://localhost:8000/
shows me the content and the log lines that I expect, as above.
So: I'm unable to reproduce the problem you report, using a configuration that seems to match your text. Can you provide a (minimal?) config file that shows the problem for you?
Francis Daly francis at daoine.org
nginx mailing list
nginx at nginx.org
More information about the nginx