VPS侦探论坛

 找回密码
 注册
查看: 6738|回复: 3

怎样把不带3w的域名重写向到带www的域名呢?

[复制链接]
发表于 2011-11-25 11:24:01 | 显示全部楼层 |阅读模式

见到管理员给出这个代码

  1. server {
  2.                 listen       80;
  3.                 server_name www.gyquan.com;
  4.                 index index.html index.htm index.php default.html default.htm default.php;
  5.                 root  /home/wwwroot/www.gyquan.com;

  6.                 include none.conf;
  7.                 location ~ .*\.(php|php5)?$
  8.                         {
  9.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  10.                                 fastcgi_index index.php;
  11.                                 include fcgi.conf;
  12.                         }

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

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

  21.                 access_log off;
  22.         }

  23. server {
  24.                 listen       80;
  25.                 server_name www.域名.com 域名.com;
  26.                 if ($host != 'www.域名.com' ) {
  27.                 rewrite ^/(.*)$ http://bbs.域名.com/$1 permanent;
  28.                 }
  29. }
复制代码


这是编辑那个文件呢?

然后,如果我想把不带www的域名,301重定向到带www的域名,我应该怎样填写呢?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2011-11-25 12:03:53 | 显示全部楼层

回复 1# 的帖子



改你的nginx.conf 或者是你的域名.conf
把xxx改成你的域名就好了
server
        {
                listen       80;
                server_name www.xxx.com xxx.com hao.xxx.com 123.xxx.com;  #二级域名
                if ($host != 'www.xxx.com' ) {          #改成你的域名 意思就是如果访问的host不是www.xxx.com就自动跳转到www.xxx.com
rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
}
                index index.html index.htm index.php default.html default.htm default.php;
                root  /home/wwwroot/xxx;   #网站目录不用改

                include xxx.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;
        }

[ 本帖最后由 68218866 于 2011-11-25 12:05 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2011-11-28 17:59:31 | 显示全部楼层

谢谢了,我试一下看看如何
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2012-7-30 05:01:58 | 显示全部楼层

回复 2# 的帖子




我也有同样的问题这样可以解决吗?试试看看。
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-23 13:26 , Processed in 0.025523 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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