Redirect (almost) all subdomains to www?

António P. P. Almeida appa at
Tue Sep 28 17:44:31 MSD 2010

On 28 Set 2010 14h15 WEST, lists at wrote:

> I have two "server" directives.
> One has:
> server_name;
> The other has:
> server_name;
> Both do what they should. However, right now any subdomain (besides
> "") is the exact same as www. I would prefer if
> things were redirected so that a user cannot use
> "" to see the website. I also don't want them
> to be able to use it without a www (e.g.
> Basically all requests should be directed to have the www subdomain
> (except for

If I understand correctly your question, something like this should to
the trick:

server {
  listen [::]:80 default_server;

You can remove the default_server flag if you can guarantee that is the *first* one that appears inside your http

--- appa

More information about the nginx mailing list