Server_Name regular expression

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


Hello!

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 example.com and www.example.com. In particular,
> a regular expression for www or nothing
> 
> I wrote the following regular expression (www\.|)example.com 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:

http://nginx.org/r/server_name

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 
reference.  

-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx mailing list