Opened 8 years ago

Closed 8 years ago

#1171 closed enhancement (wontfix)

Clarify $server_name variable with regex server_name directive

Reported by: davidjb Owned by:
Priority: minor Milestone:
Component: documentation Version: 1.10.x
Keywords: Cc:
uname -a: N/A
nginx -V: N/A

Description

The documentation for $server_name mentions the following:

$server_name
    name of the server which accepted a request.

When using the server_name directive with regex and captures (like in the documentation), it was unclear to me without testing what the $server_name variable would end up being. After looking at the source, I can now see the variable is always the string literal of the matching server_name.

I'd suggest adding an additional line to the documentation for $server_name to clarify the expected value of this variable, such as the following:

$server_name

name of the server which accepted a request.

If the server_name directive contains one or more regular expressions, $server_name will be the string literal of the matching regular expression; it is not evaluated in this variable.

Change History (1)

comment:1 by Maxim Dounin, 8 years ago

Resolution: wontfix
Status: newclosed

The server_name directive documentation explicitly says that the first name specified will be used as the primary name:

Sets names of a virtual server, for example:

server {
    server_name example.com www.example.com;
}

The first name becomes the primary server name.

It doesn't matter if the name uses wildcards, or regular expressions - the name will be as written in the configuration. And I think it is clear form the server_name directive description.

Additionally, the suggested text is not technically correct:

  • The "will be the string literal of the matching regular expression" claim is wrong. Instead, it will be the name of the matching server, and this name may be quite different from the matching regular expression if the expression matched isn't the name of the server.
  • It is not clear what "it is not evaluated in this variable" mean to say. Evaluating a regular expression produces a binary result (match or no match), and it is obvious that the regular expression is not evaluated. It may mean to say "not the string matched by the regular expression". But adding such a clarification is more or less useless as it contradicts the whole the whole idea of $server_name. It is mean to specify a string form the configuration, in contrast to $host which is from the client request.

Overall, I don't see any improvement in the clarification suggested.

Note: See TracTickets for help on using tickets.