Server_Name regular expression

Maxim Dounin mdounin at
Thu Aug 29 09:37:52 UTC 2013


On Thu, Aug 29, 2013 at 05:01:01AM -0400, christospap wrote:

> I would like to syntax a regular expression which will match two server
> names. The server names are and In particular,
> a regular expression for www or nothing
> I wrote the following regular expression (www\.|) Nginx
> configuration file is compatible with Perl programming language. While it
> should work, it doesn't seem to work. I cannot find the proper regular
> expression. Does anyone have an idea how to synatx the regular expression?

How to use regular expressions in server_name directive is 
documented here:

Note that regular expressions must be preceeded with "~" to 
distinguish them from normal names.

Syntax of regular expressions per se is documented in the PCRE 
library manual pages, see "man pcresyntax" for quick syntax 

Maxim Dounin

More information about the nginx mailing list