2

I have a machine foo00 whos CNAME is foo. With nginx I can access my site from the following URLs:

foo/
foo00/
foo.domain.local/
foo00.domain.local/

How can I configure nginx so that all are redirected foo.domain.local?

I tried the following:

server {

    listen 80;
    server_name foo.domain.local;
    return 301 $scheme://$host$request_uri;

}

This redirects foo/ to foo.domain.local/ but not foo00/ or foo00.domain.local. Any ideas?

2 Answers 2

1

Add another server block for the other domains you want to redirect:

server {
    listen 80;
    server_name foo00.domain.local;

    return 301 http://foo.domain.local;
}

Or if you want to preserve the URI, you can use this:

return 301 http://foo.domain.local$request_uri;
0

Add all your domains like

server_name sub.domain.tld domain.tld othersub.domain.tld andsoon.tld;

(don't forget the ";" at the end of directives).

Take a look the the rewrite documentation of nginx for further options regarding adding possible URL parameters if you need that.

1
  • I changed server_name to foo.domain.local foo00.domain.local but it doesn't make a difference. This is a single a machine, single domain, I just want everything redirect using the CNAME.
    – iiSeymour
    Apr 1, 2014 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .