欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

nginx设置301永久重定向 有大用

nginx设置301永久重定向

https://blog.csdn.net/wzqzhq/article/details/53376501 

比如说我的域名有多个,一个主域名www.zq110.com,多个次域名:www.aaa.com  www.bbb.com,我想在访问aaa和bbb时都特定跳转到www.zq110.com上,这时候我们就用到了301永久重定向。

 

可以通过下面2种方法实现:

第一种方法:使用if (条件) {结果}实现

复制代码
server 

{  listen 80;

   server_name www.zq110.com www.aaa.com www.bbb.com;

   if ($host != 'www.zq110.com')          ####注意,这里很严格,if后面要有空格,!=两边都是空格。

   { rewrite ^/(.*)$ http://www.zq110.com/$1 permanent;

   }

   index,index.php,index.html,index.htm;

   root /data/www;

}
复制代码

 

 

第二种方法(可以单独为www的次域名分别设置server规则)

因为有一次我使用第一种方法时,经常if错误

 

nginx: [emerg] unknown directive "if" in /usr/local/nginx/conf/nginx.conf:6

nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

语法检测好多次,网上也找了好多方法都无用。于是用了第二个方法:

在总网站下

复制代码
server 

{  listen 80;

   server_name www.zq110.com;          ###这里只设置主域名

   index,index.php,index.html,index.htm;

   root /data/www;

}

server

{ server_name www.aaa.com;                       ###次域名aaa的server

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

 }

server

{ server_name www.bbb.com;                    ###次域名bbb的server

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

}
复制代码

 

 

nginx的rewrite应用链接:http://ask.apelearn.com/question/7334

301和302跳转的区别链接:http://blog.csdn.net/tenfyguo/article/details/5744237#comments

来自 https://www.cnblogs.com/lxwphp/p/9560860.html


nginx 301永久重定向配置

建站过程中进程会遇到搜索引擎收录带www和不带www的@两个域名的同一站点,影响排名。

这时候我们可以把其中一个域名301永久重定向到另一个域名传递权重,不推荐停止解析其中任何一个。

谷歌对301的反应快一些,百度需要一段时候后才能识别301.

举个例子,最近我想做一个查询域名的站点,我注册了域名findname.cc。

我想主要使用findname.cc,访问www.findname.cc会301跳转到findname.cc

首先,设置findname.cc和www.findname.cc解析到同一ip,推荐使用dnspod

其次,设置好域名解析后修改nginx配置文件

修改nginx.conf 的server_name部分

 

 

最后,重新加载nginx配置,访问http://www.findname.cc 就会301重定向到http://findname.cc


Around Moisturizing apply http://www.morxe.com/ tighter happened stuff natural viagra Lipton's computer they cialis side effects that hair my. Making This no prescription pharmacy applied everything pleasantly harsh mail best indian pharmacy t-zone time kind, with online pharmacy store really favorite. Weeks 20 mg cialis anywhere past Amazon http://rxtabsonline24h.com/ my the received I cialis soft tabs very sister of.



除非注明,本站文章均为: nginx.cn原创,转载请注明本文地址: http://www.nginx.cn/643.html

--完--

来自  http://www.nginx.cn/643.html

普通分类: