nginx 域名重定向

nginx 域名重定向

  • 在conf/vhost/中添加 test02.conf 文件
server
{
    listen 80;
    server_name www.test02.com test02.com test2.com;
    index index.html index.htm index.php;
    root /data/www/test02;
    if ($host != 'test.com' ) {
        rewrite  ^/(.*)$  http://test01.com/$1  permanent;
    }
}

除去test02.com 外 其他 www.test02.com或者 test2.com都进行跳转,返回状态码为301

  • server_name后面支持写多个域名,这里要和httpd的做一个对比
  • permanent为永久重定向,状态码为301,如果写redirect则为302

posted on 2018-01-04 01:51  游荡的鱼  阅读(230)  评论(0编辑  收藏  举报

导航