nginx 配置rewrite笔记:

通过下面的示例来说明一下,
1. 先说说location :
location 表示匹配传入的url地址,其中配置符有多种,各种情况的意义不一样:
location ^~ /public/ {
root /data/wwwroot/a.php.abc.cc;
}
location ^~ /public/ 表示匹配以 “/public/” 开头的url,匹配成功执行其中的内容,执行完毕后停止并退出。
location / {
root /data/wwwroot/a.php.abc.cc;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
}

location / { ... } 表示匹配所以的url,匹配成功执行其中的内容,执行完毕后停止并退出。

rewrite ^/e10adc3949ba[/]?$ /e10adc3949ba.php last; 表示将 /e10adc3949ba 或 /e10adc3949ba/ 开头的url修改为 /e10adc3949ba.php
rewrite ^/e10adc3949ba/([a-z]*/[a-z]*)/([a-z]*)$ /e10adc3949ba.php?c=$1&a=$2 last; 表示将pathinfo地址转换为参数地址,
比如原url: /e10adc3949ba/help/manage/lists 转换后:/e10adc3949ba.php?c=help/manage&a=lists

server {
listen 80;
server_name a.php.abc.cc;

access_log /data/wwwlogs/a.php.abc.cc_nginx.log combined;
index index.html;
root /data/wwwroot/a.php.abc.cc;

location ^~ /public/ {
root /data/wwwroot/a.php.abc.cc;
}

location ^~ /datas/ {
root /data/wwwroot/a.php.abc.cc;
}

rewrite ^/e10adc3949ba[/]?$ /e10adc3949ba.php last;
rewrite ^/e10adc3949ba/([a-z]*/[a-z]*)/([a-z]*)$ /e10adc3949ba.php?c=$1&a=$2 last;
rewrite ^/e10adc3949ba/([a-z]*/[a-z]*)/([a-z]*)\?(.*)$ /e10adc3949ba.php?c=$1&a=$2&$3 last;

location ^~ /e10adc3949ba {
root /data/wwwroot/a.php.abc.cc;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/e10adc3949ba.php;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
break;
}

rewrite ^/([a-z]*)/([a-z]*)$ /index.php?m=home&c=$1&a=$2 last;
rewrite ^/([a-z]*)/([a-z]*)\?(.*)$ /index.php?m=home&c=$1&a=$2&$3 last;

location / {
root /data/wwwroot/a.php.abc.cc;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
}
}

整个配置的意思为:

1.优先匹配/public和/datas,这两个中包含的是公用的可公开的文件,比如js,css,自定义文件等等。
2. 如果1没有匹配上,则剩下的都是php文件。php分为两类,一个是e10adc3949ba.php (后台入口),另一个是index.php(前台入口)。
3. 先配置后台,后台的都需要包含 /e10adc3949ba , 通过这个前缀对后台进行匹配。匹配到就调用后台入口执行,执行完毕退出。
4. 上下的默认都是前台内容,先进行url转换,将phpinfo格式的url转换为参数模式。然后调用index.php入口文件执行。
5. 最后的匹配还包含了 / 的情况和其他错误的地址情况都会匹配上。错误处理由代码完成。

nginx 配置rewrite 笔记的更多相关文章

  1. nginx配置rewrite

    1. uri  和 url读取区别 区别就是URI定义资源,而URL不单定义这个资源,还定义了如何找到这个资源. 比如说,一个服务器上,到一个文件夹/网页的绝对地址(absolute path)就是U ...

  2. nginx 配置 rewrite 跳转

    在访问 test.com 网站时,会自动跳转到 www.test.com ,这是因为该网站做了 URL rewrite 重定向,一般网页重定向跳转分为两种,301 和 302 :301,302 都是H ...

  3. nginx配置-Rewrite

    rewrite功能就是,使用nginx提供的全局变量或自己设置的变量,结合正则表达式和标志位实现url重写以及重定向.rewrite只能放在server{},location{},if{}中,并且只能 ...

  4. Nginx配置rewrite过程介绍

    创建rewrite语句 vi conf/vhost/www.abc.com.conf #vi编辑虚拟主机配置文件 文件内容 server { listen 80; server_name abc.co ...

  5. nginx配置rewrite总结

    1.rewrite regex replacement [flag] 2.flag为break时,url重写后,直接使用当前资源,不在执行location里其他语句,完成本次请求,地址栏url不变. ...

  6. 【Nginx】Nginx配置REWRITE隐藏index.php

    只需要在server里面加上 if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; }

  7. Nginx配置REWRITE隐藏index.php

    server { listen 80; server_name localhost; root D:\workspace\PHP\Atromic; location / { index index.p ...

  8. Nginx配置location总结及rewrite规则写法

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 32.0px "Helvetica Neue"; color: #323333 } p. ...

  9. rewrite规则写法及nginx配置location总结

    rewrite只能放在server{},location{},if{}中,并且只能对域名后边的除去传递的参数外的字符串起作用. 例如http://seanlook.com/a/we/index.php ...

随机推荐

  1. ConfigHelper.cs

    using System.Configuration; using System.IO; /// <summary> /// 配置文件辅助类 /// </summary> pu ...

  2. js-url打开方式

    引用自 : 老张的博客 *.location.href 用法: top.location.href="url"          在顶层页面打开url(跳出框架) self.loc ...

  3. svg path详解

    svg的<path>标签具有强大的功能,主要包括以下命令 M(move to) 参数:x,y L(line to) 参数:x,y H 参数:x V 参数:y C S Q T Z 参考:

  4. android studio怎么分享项目到Git@OSC托管

    鄙人初次发表,如有不妥之处,敬请批评指正 1,安装git. git下载地址:http://git-scm.com/downloads/ 2,在AS 的File->Settings->Ver ...

  5. 字符串对象-String

    新建字符串对象 ① 直接赋值 ② 构造函数 ③ 转换函数 1    length              字符串对象属性 2    match()  null     跟php中的preg_matc ...

  6. [译]关于iOS和OS X废弃的API你需要知道的一切

    原文: Everything You Need to Know about iOS and OS X Deprecated APIs 如你所知,已废弃(Deprecated)的API指的是那些已经过时 ...

  7. 6. Adapter Class/Object(适配器)

    意图: 将一个类的接口转换成客户希望的另外一个接口.Adapter 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 适用性: 你想使用一个已经存在的类,而它的接口不符合你的需求. 你想 ...

  8. windows下mongodb权限设置解决方法

    mongodb简介: MongoDB 是一个跨平台的,面向文档的数据库,提供高性能,高可用性和可扩展性方便. MongoDB工作在收集和文件的概念. MongoDB默认设置为无权限访问限制,所以可以直 ...

  9. win10 virtualbox5, ubuntu16.04 xshell5配合使用

    这个搭配很好用,各软件的安装很容易,ubuntu安装进virtualbox后安装增强功能,然后将网络连接方式改为桥接,直接改为桥接就可以了,其他的不用变,这个比以前的版本好用多了.这个桥接解决了宿主机 ...

  10. 设置secureCRT的鼠标右键为弹出文本操作菜单功能

    options菜单下的 global options 页面的 terminal 中的 mouse 子菜单对 paste  on  right button 的选项取消勾选即可.