阿里云Nginx服务器配置301重定向

网上查了一下linux 301重定向的代码,都是说要在 .htaccess 文件中添加重定向代码,但是我试了好多次,都没有成功。这是怎么回事?莫非这些代码都有错误?
于是,我又继续查找资料,最终在阿里云论坛里找到了答案,不看不知道,一看吓一跳哇,方法非常简单,不是在.htaccess 文件里修改,而是要在 .conf 文件里修改,就是你绑定域名的那个文件里修改,如果你用的阿里云自带的系统,那么这个.conf文件在 /alidata/server/nginx-1.2.5/conf/vhosts 这个目录里。打开这个文件phpwind.conf编辑:

server {
        listen       80; 
        server_name  www.xiaochunchun.com xiaochunchun.com;
        if ($host != 'www.xiaochunchun.com' ) {
          rewrite ^/(.*)$ http://www.xiaochunchun.com/$1 permanent;
        } 
        index index.html index.htm index.php; 
        root /alidata/www/ycsc/web; 
        location ~ .*\.(php|php5)?$ 
        { 
                #fastcgi_pass  unix:/tmp/php-cgi.sock; 
                fastcgi_pass  127.0.0.1:9000; 
                fastcgi_index index.php; 
                include fastcgi.conf; 
        } 
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ 
        { 
                expires 30d; 
        } 
        location ~ .*\.(js|css)?$ 
        { 
                expires 1h; 
        } 

        include /alidata/server/nginx/conf/rewrite/phpwind.conf; 
        access_log  /alidata/log/nginx/access/ycsc.log; 
}

检验是否配置正确,连接远程控制

cd /alidata/server/nginx/sbin/

输入命令:

./nginx -t

出现如下两行,即表示配置正确。

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

重启nginx~ 输入指令(仍在在sbin目录下)~

./nginx -s reload

测试成功,利用站长之家检测:

http://tool.chinaz.com/pagestatus

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值