nginx.conf redirect multiple conditions

前端 未结 6 1814
傲寒
傲寒 2021-01-30 03:46

I want to redirect requests on two conditions using nginx.

This doesn\'t work:

  if ($host = \'domain.com\' || $host = \'domain2.com\'){
    rewrite ^/(         


        
6条回答
  •  被撕碎了的回忆
    2021-01-30 04:44

    another possibility would be

    server_name domain.com domain2.com;
    set $wanted_domain_name domain.com;
    if ($http_host != $wanted_domain_name) {
        rewrite  ^(.*)$  https://$wanted_domain_name$1;
    }
    

    so it will redirect all to one specific but it's based on the usecase i guess

提交回复
热议问题