How to redirect to a different domain using NGINX?

前端 未结 8 876
旧时难觅i
旧时难觅i 2020-12-02 07:10

How can I redirect mydomain.com and any subdomain *.mydomain.com to www.adifferentdomain.com using NGINX?

8条回答
  •  青春惊慌失措
    2020-12-02 07:49

    You can simply write a if condition inside server {} block:

    server { 
    
        if ($host = mydomain.com) {
            return 301 http://www.adifferentdomain.com;
        } 
    }
    

提交回复
热议问题