P
P
Pista2020-11-18 20:12:43
Nginx
Pista, 2020-11-18 20:12:43

How to redirect domain aliases through Nginx?

The domain has several aliases.
server_name site1.ru site2.ru site3.ru

I need to redirect site1.ru/page for example to google.com
And site2.ru/landing Redirect to yandex.ru

if ($http_host = 'site1.ru') {
    rewrite ^(.*) https:/google.com permanent;
  }

if ($http_host = 'site2.ru') {
    rewrite ^(.*) https://yandex.ru permanent;
  }


Is there another option to get by with one block?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2020-11-18
@Pista

Why do with one block if your processing is different? Ceteris paribus, it is better to make separate server blocks than to crutch with ifs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question