zoukankan      html  css  js  c++  java
  • Nginx笔记总结十一:Nginx重写规则指南

    依赖PCRE库,需要安装pcre,最多循环10次,超过后返回500错误,

    1.       rewrite模块指令

    break:完成当前设置的重写规则,停止执行其他的重写规则

    if:  if () {...}

    return:停止处理并返回客户端状态码

    rewrite: rewrite regex replacement flag

    last:停止处理重写模块指令,之后搜索location与更改后的URI匹配

    break:完成重写

    redirect:返回302临时重定向,如果用http://则被使用

    permanent:返回301永久冲定向

    rewrite_log:重写日志,  rewrite_log on|off;

    set:设置变量

    2.       重写规则组成部分:

    任何重写规则的第一部分都是一个表达式

    可以使用括号来捕获,$1是第一个括号中的值,依次类推

    重写第二部分是URI

    重写第三部分是标记

    实例:

    location / {
    
    error_log logs/rewrite.log notice;
    
    rewrite '^/images/([a-z]{2})/([a-z0-9]{5})/(.*).(png|jpg|gif)$' /data?file=$3.$4;
    
    }
    
     
    
    location /data {
    
    access_log logs/images.log main;
    
    root /data/images;
    
    try_files /$arg_file /image404.html;
    
    }
    
    location =/image404.html {
    
    return 404 "image not found
    ";
    
    }
  • 相关阅读:
    Html、Vue——本地文件上传弹框+读取本地文件内容
    git-基本操作
    Selenium(二)---无界面模式+滑动底部
    Selenium(一)---Selenium的安装和使用
    Nginx+win10安装配置
    Tinghua Data Mining 9
    Tinghua Data Mining 8
    Tinghua Data Mining 7
    Tinghua Data Mining 6
    Tinghua Data Mining 5
  • 原文地址:https://www.cnblogs.com/djoker/p/6396463.html
Copyright © 2011-2022 走看看