default nginx rewrite with regexp

Francis Daly francis at
Mon Nov 17 19:14:17 UTC 2014

On Mon, Nov 17, 2014 at 02:22:48PM +0100, Yoann Moulin wrote:

Hi there,

> I'm working on a default server_name that match everything but www.domain.tld
> then rewrite to www.domain.tld.

It sounds like you may have better luck letting other server{} blocks use
expected server_name:s; and just let the default match everything else.

But I'm not exactly sure what it is that you do want to do and don't
want to do.

> I must be able to make a difference between and
> first must rewrite second, to

Have you a list or a pattern of which endings should match the first
pattern, and which the second? Because if you do not, you cannot
expect nginx to know that should be handled differently

> But I don't find any clean solution. Is there a solution for that ? or I must
> still list all domains in my vhost ?

If you can specify the problem exactly, it may be possible to arrive at a solution.

If you can't, it probably won't be.

What should happen to a request for Or

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list