VPS侦探论坛

 找回密码
 注册
查看: 5151|回复: 5

请教301重定向

[复制链接]
发表于 2014-5-6 13:36:01 | 显示全部楼层 |阅读模式

按军哥教程修改301重定向,2个网站,一个成功,一个不成功
测试了几次,修改几次还是不成功,只好发帖求助了

  1. log_format  www.xxx.com  '$remote_addr - $remote_user [$time_local] "$request" '
  2.              '$status $body_bytes_sent "$http_referer" '
  3.              '"$http_user_agent" $http_x_forwarded_for';
  4. server
  5.         {
  6.                 listen       80;
  7.                 server_name www.xxx.com xxx.com;
  8.                 index index.html index.htm index.php default.html default.htm default.php;
  9.                 root  /home/wwwroot/www.xxx.com;

  10.                 include none.conf;
  11.                 location ~(plus|member|special|include|data|a|images|templets|uploads|dede)/(.*)\.(pl|php|cgi|asp|aspx|py|tpl|jsp) {return 400;}
  12.                 location ~ .*\.(php|php5)?$
  13.                         {
  14.                                 try_files $uri =404;
  15.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  16.                                 fastcgi_index index.php;
  17.                                 include fcgi.conf;
  18.                         }

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

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

  27.                 access_log  /home/wwwlogs/www.xxx.com.log  www.xxx.com;
  28.         }

  29. server {
  30. server_name xxx.com;
  31. return 301 $scheme://www.xxx.com$request_uri;
  32. }
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2014-5-6 13:36:53 | 显示全部楼层


  1. [root@VPS-xxxxx ~]# /etc/init.d/nginx restart
  2. Restarting nginx daemon: nginxnginx: [warn] conflicting server name "xxx.com" on 0.0.0.0:80, ignored
  3. nginx: [warn] conflicting server name "aaa.com" on 0.0.0.0:80, ignored
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2014-5-6 13:45:20 | 显示全部楼层

你把
  1.                 if ($host != 'www.xxx.com' ) {
  2.                 rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
  3.                 }
复制代码


放在
  1. server
  2.         {
  3.                 listen       80;
  4.                 server_name www.xxx.com xxx.com
复制代码


这段下面重启NGINX就生效了
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2014-5-6 13:46:17 | 显示全部楼层



上面本身有server {
server_name xxx.com;
你下面在写一段根本没什么意义
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2014-5-6 14:51:53 | 显示全部楼层

域名重复要想xxx.com跳到www.xxx.com,把第一个server_name里的xxx.com删掉,重启

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2014-5-6 14:56:22 | 显示全部楼层

试了楼上回贴的也可以,但好像是不好

用了军哥的方法OK

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-25 15:25 , Processed in 0.027349 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表