Q: about "best" way for remove www in hostname in nginxish

Dear readers,

after reading


and googleing


I have a ‘best solution’ question.

I have the following customer request.

The ‘normal User’ type almost every time a www.subdomain.domain.at into
they browser,
which does not exist but the subdomain.domain.at exists.

I would now add the follwing into my nginx.conf.

server {
server_name ~^(www.)?(?.+)$;

return http://$domain/;

Is this the cleanest way in nginxish?

Thanks for help

I just do

server {
listen 80;
server_name was.foo.com;
rewrite ^ http://foo.com$uri permanent;

That’s how I do it, except that I hard-code a list of the domains I
want to redirect. Otherwise, I’d have built a service that could be
trivially used by anyone else for their own domain. Wildcards are bad,
mmkay? :wink:


I do:
if ($host ~* "^www.(.)$") {
set “$domain” “$1”;
rewrite (.
) http://$domain$uri permanent;

B. R.

On Mon, May 6, 2013 at 12:50 PM, Jonathan M.

I remember this and now also where I have seen it :wink:

Thanks for all feedback.

I will try the Solution written in first post.

Br aleks

Am 06-05-2013 20:30, schrieb B.R.:

[email protected]
nginx Info Page [1]

nginx mailing list
[email protected]
nginx Info Page [1]


You’re right, my solution sucks… but it has the benefit of being
I’ll look into it.

Glad you found a solution, though. ;o)

B. R.