zoukankan      html  css  js  c++  java
  • nginx目录路径重定向[转]

    如果希望域名后边跟随的路径指向本地磁盘的其他目录,而不是默认的web目录时,需要设置nginx目录访问重定向. 应用场景:dashidan.com/image自动跳转到dashidan.com/folderName/image.nginx目录路径重定向的四种实现方式.修改root映射,通过Nginx rewrite内部跳转,设置别名alias映射实现,通过nginx的permanent 301绝对跳转实现.

    1 nginx修改root映射
    修改root映射实现nginx目录访问重定向是最简单的方式, 推荐采用这一种.

    location /image {
    root /folderName;
    }
    2 通过nginx rewrite内部跳转实现访问重定向
    nginx配置代码示例:

    location /image {
    rewrite ^/image/(.*)$ /folderName/image/$1 last;
    }
    3 nginx设置别名alias映射实现
    配置示例:

    location /image {
    alias /folderName/image; #这里写绝对路径
    }
    4 通过nginx的permanent 301绝对跳转实现
    配置示例:

    location /image {
    rewrite ^/image/(.*)$ http://dashidan.com/folderName/image/$1;
    }
    5 通过判断uri实现页面跳转
    配置示例:

    if ( $request_uri ~* ^(/image)){
    rewrite ^/image/(.*)$ /folderName/image/$1 last;
    }

    转:https://dashidan.com/article/webserver/nginx/4.html

  • 相关阅读:
    LintCode "Binary Tree Serialization"
    LeetCode "Find the Duplicate Number"
    LintCode "Route Between Two Nodes in Graph"
    LintCode "Search a 2D Matrix II"
    LintCode "Submatrix Sum"
    LintCode "Sort Letters by Case"
    LeetCode "Peeking Iterator"
    LintCode "Sort Colors II"
    LeetCode "Move Zeroes"
    LintCode "Update Bits"
  • 原文地址:https://www.cnblogs.com/uglyliu/p/9312896.html
Copyright © 2011-2022 走看看