Nginx利用rewrite进行文件转移

来源:互联网 发布:daum potplayer mac版 编辑:程序博客网 时间:2024/04/30 14:44
1、创建测试战点
server {
        listen       80;
        server_name  localhost;
        root /www/web/;
        index index.php index.html index.htm;
2、在网站根目录建立test1  test2 两个目录,
test1 为第一块盘挂载的,例如100G的固态硬盘,预计只存储一个月数据,一个月后数据转移到test2
test2 为第二快盘挂载的,例如5T的机械硬盘,只存储历史数据,

3、在站点目录下test1下建立91cto目录,在该目录下建立index.html  
访问测试可以http://192.168.1.187/test1/91cto/



4、好戏来了,
现在进行rewrite重写

server {
        listen       80;
        server_name  localhost;
        root /www/web/;
        index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
   rewrite ^/test1/(.*)$  /test2/$1 last;
   }
}


5、重新加载Nginx后 将test1里面的所有内容转移到test2

此时再访问http://192.168.1.187/test1/91cto/
应该报错404,因为test1里面什么都么有了。

6、清除缓存再访问,或者换浏览器访问

还能从test1里面访问到内容,

7、成功的进行了转移。
0 0
原创粉丝点击