`
jgsj
  • 浏览: 965579 次
文章分类
社区版块
存档分类
最新评论

nginx 301重定向,无www,www

 
阅读更多

由于网站需要,把不带www和带www的域名合并到一起,而新网的又没有了转向功能,只能由服务器下手。谷歌知道需要使用301定向。以便phodal.com转向www.phodal.com

原来的配置文件如下

server
      {
          listen       80;
          server_name phodal.com www.phodal.com;
          index index.html index.htm index.php default.html default.htm default.php;
          root  /home/wwwroot/onelone.com;

          include typecho.conf;
          location ~ .*\.(php|php5)?$
                  {
                          fastcgi_pass  unix:/tmp/php-cgi.sock;
                          fastcgi_index index.php;
                          include fcgi.conf;
                  }

          location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                  {
                          expires      30d;
                  }

          location ~ .*\.(js|css)?$
                  {
                          expires      12h;
                  }

          access_log off;
      }

将phodal.com删除再添加

server {
    server_name phodal.com;
    rewrite ^(.*) http://www.phodal.com$1 permanent;
}

由于最后就如下所示:


(转载请保留;Phodal's 博客)


server
      {
          listen       80;
          server_name www.phodal.com;
          index index.html index.htm index.php default.html default.htm default.php;
          root  /home/wwwroot/onelone.com;

          include typecho.conf;
          location ~ .*\.(php|php5)?$
                  {
                          fastcgi_pass  unix:/tmp/php-cgi.sock;
                          fastcgi_index index.php;
                          include fcgi.conf;
                  }

          location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                  {
                          expires      30d;
                  }

          location ~ .*\.(js|css)?$
                  {
                          expires      12h;
                  }

          access_log off;
      }
server {
    server_name phodal.com;
    rewrite ^(.*) http://www.phodal.com$1 permanent;
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics