VPS侦探论坛

 找回密码
 注册
查看: 18083|回复: 9

[Apache] nginx 301重定向做法

[复制链接]
发表于 2010-10-16 22:24:58 | 显示全部楼层 |阅读模式

找了半天,论坛里面没有    所以贴出来
直接在vhos的conf里面添加
server_name www.yoursite.com yoursite.com;
    if ($host != 'www.yoursite.com' ) {
        rewrite  ^/(.*)$  http://www.yoursite.com/$1  permanent;
}

yoursite   你的域名。

评分

参与人数 1威望 +2 收起 理由
licess + 2

查看全部评分

美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2010-10-31 22:51:49 | 显示全部楼层


做个记号,谢谢你了
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2010-11-3 15:57:57 | 显示全部楼层

很奇怪,我试了一下,这个方法好像不行。
后来在网上搜索找到另外一个方法成功了。

编辑/usr/local/nginx/conf/nginx.conf,在最后一个}上面加上下面的几行
  1. server
  2. {
  3. server_name chinabike.tv;
  4. rewrite ^(.*) http://bbs.chinabike.tv/$1 permanent;
  5. }
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2011-8-11 20:48:32 | 显示全部楼层



  1. server
  2. server_name www.域名.com 域名.com;
  3.     if ($host != 'www.域名.com' ) {
  4.         rewrite  ^/(.*)$  http://bbs.域名.com/$1  permanent;
  5. }
  6.         {
  7.                 listen       80;
  8.                 server_name www.gyquan.com;
  9.                 index index.html index.htm index.php default.html default.htm default.php;
  10.                 root  /home/wwwroot/www.gyquan.com;

  11.                 include none.conf;
  12.                 location ~ .*\.(php|php5)?$
  13.                         {
  14.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  15.                                 fastcgi_index index.php;
  16.                                 include fcgi.conf;
  17.                         }

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

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

  26.                 access_log off;
  27.         }
复制代码



就是把
  1. server_name www.域名.com 域名.com;
  2.     if ($host != 'www.域名.com' ) {
  3.         rewrite  ^/(.*)$  http://bbs.域名.com/$1  permanent;
  4. }
复制代码

插到第一行的
  1. server
复制代码

后面,然后保存。
请指教。
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2011-8-11 21:27:44 | 显示全部楼层

  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. }
复制代码

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

发表于 2011-8-12 09:39:03 | 显示全部楼层

哦,明白了。
谢军大,今天回去试一下。
发表于 2011-8-15 16:59:26 | 显示全部楼层

谢谢
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2011-9-30 20:40:38 | 显示全部楼层

回复 7# 的帖子


你好军哥
如果有两个域名,要怎么样写叱?
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2011-9-30 21:22:20 | 显示全部楼层

回复 8# 的帖子


写二个server_name段就行了
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2011-10-24 12:47:04 | 显示全部楼层



谢谢分享 试试看 测试成功了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-28 02:19 , Processed in 0.028844 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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