您的位置:首页 > 运维架构 > Nginx

nginx 301 域名跳转

2014-11-06 17:36 225 查看
假设两个域名 cai.com www.cai.com,需要把所有cai.com 的访问都跳转到 www.cai.com

server {

    listen       80 ;

    server_name  _;

        index index.html index.htm index.php;

        root /alidata/www/;

        location ~ .*\.(php|php5)?$

        {

                fastcgi_pass  127.0.0.1:9000;

                fastcgi_index index.php;

                include fastcgi.conf;

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

        {

                expires 30d;

        }

        location ~ .*\.(js|css)?$

        {

                expires 1h;

        }

        access_log  /alidata/log/nginx/access/default.log;

}

server {

    listen       80 default;

    server_name  www.cai.com;

        index index.html index.htm index.php;

        root /alidata/www/114/trunk/;

        location ~ .*\.(php|php5)?$

        {

                fastcgi_pass  127.0.0.1:9000;

                fastcgi_index index.php;

                include fastcgi.conf;

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

        {

                expires 30d;

        }

        location ~ .*\.(js|css)?$

        {

                expires 1h;

        }

        access_log  /alidata/log/nginx/access/114.log;

}

server {

    server_name cai.com;

    rewrite "^/(.*)" http://www.cai.com/$1 permanent;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: