1. uri  和 url读取区别

区别就是URI定义资源,而URL不单定义这个资源,还定义了如何找到这个资源。

比如说,一个服务器上,到一个文件夹/网页的绝对地址(absolute path)就是URI。

Nginx的rewirte是针对 uri的 不是url.

2. location的使用

    location / {
rewrite ^.*$ /index.php last;
}
# /是通用的目录 所有没有匹配的rewite的最后都会用/匹配
location ~ ^/asset/ {
root /home/users/work/webroot/public/fe;
}
#~ 开头表示区分大小写的正则匹配 这里是匹配下一级目录/asset/开头
#~* 开头表示不区分大小写的正则匹配
#!~和!~*分别为区分大小写不匹配及不区分大小写不匹配 的正则 location ~ ^/dep/ {
root /home/users/work/webroot/public/fe;
}
# dep同上, 匹配/dep/目录, 当访问/dep目录时, 网站的根目录会变为
fe
location ~ ^/page/.*/asset-\d+/ {
root /home/users/work/webroot/public/fes;
}
# 此处为匹配page目录下asset后有数字的目录,/page/目录时, 网站的根目录会变为fes location ~\.php$ {
root /home/users/work/webroot/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi.conf;
}
#以上结果都不匹配, location是.php结尾,注意这里是\不是/ 用来转义.的, $是以.php结尾的意思, 这里就把所有的.php的请求都重定向到/home/users/work/webroot/public 下, 并且使用fastcgi协议通过127.0.0.1:9000转发请求, fastcgi_param定义各个参数, 具体含义如下表, 这里的$document_root$fastcgi_script_name 就是/home/users/work/webroot/public/index.php 请求脚本的路径和名称

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径
fastcgi_param QUERY_STRING $query_string; #请求的参数;如?app=123
fastcgi_param REQUEST_METHOD $request_method; #请求的动作(GET,POST)
fastcgi_param CONTENT_TYPE $content_type; #请求头中的Content-Type字段
fastcgi_param CONTENT_LENGTH $content_length; #请求头中的Content-length字段。


fastcgi_param SCRIPT_NAME $fastcgi_script_name; #脚本名称
fastcgi_param REQUEST_URI $request_uri; #请求的地址不带参数
fastcgi_param DOCUMENT_URI $document_uri; #与$uri相同。
fastcgi_param DOCUMENT_ROOT $document_root; #网站的根目录。在server配置中root指令中指定的值
fastcgi_param SERVER_PROTOCOL $server_protocol; #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。


fastcgi_param GATEWAY_INTERFACE CGI/1.1;#cgi 版本
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;#nginx 版本号,可修改、隐藏


fastcgi_param REMOTE_ADDR $remote_addr; #客户端IP
fastcgi_param REMOTE_PORT $remote_port; #客户端端口
fastcgi_param SERVER_ADDR $server_addr; #服务器IP地址
fastcgi_param SERVER_PORT $server_port; #服务器端口
fastcgi_param SERVER_NAME $server_name; #服务器名,域名在server配置中指定的server_name


#fastcgi_param PATH_INFO $path_info;#可自定义变量


# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;


在php可打印出上面的服务环境变量
如:echo $_SERVER['REMOTE_ADDR']


还见过一个简便的使用框架的写法,所有的location凡是uri指定的文件不存在则重定向到 /index.php?s=$uri上。
location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } }

nginx配置rewrite的更多相关文章

  1. nginx 配置rewrite 笔记

    nginx 配置rewrite笔记: 通过下面的示例来说明一下,1. 先说说location : location 表示匹配传入的url地址,其中配置符有多种,各种情况的意义不一样: location ...

  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. 软件测试--测试Demo

    视频地址(第二课时):https://pan.baidu.com/s/1gfLVC2n 软件安装好了! 软件默认的浏览器是火狐. 如果需要IE,chrome,都在前一篇的安装包里有. 测试结果 视频里 ...

  2. CAD打开文件总是弹出要求选择字体怎么办

    CAD打开文件总是弹出要求选择字体怎么办1.在C:\Documents and Settings\下搜索acad.fmp文件,双击用记事本打开acad.fmp文件,在最后添加内容,上面几行本来就有,不 ...

  3. 安卓手机上运行 PC-E500 程序

    目录 第1章安卓手机上运行 PC-E500 程序    1 1 PockEmul    1 2 下载    1 3 打包BASIC程序    2 4 配置PC-E500模拟器    5 5 载入e50 ...

  4. zoj 2833 friendship

    zoj 2833这次真的很顺利了..居然是因为数组的大小没有符合要求,瞎折腾了很久..没有注意到要求范围,真是该死! 想法很简单,就是定义一个父结点数组,下标 i 表示这个元素,初始化为 -1表示 这 ...

  5. pc, 手机全屏

    全屏 1  div{ position:absolute/relative/fixed; top:0; bottom:0; left:0; right:0;} 2 <!doctype html& ...

  6. VaildForm 自定义提示消息

    ValidForm插件提供了7种提示效果,其中有四种自定义效果,具体访问地址:http://validform.rjboy.cn/demo.html 个人偏爱其中两种,即 l 提示效果四:[自定义提示 ...

  7. iOS开发UI篇—Date Picker和UITool Bar控件简单介绍

    iOS开发UI篇—Date Picker和UITool Bar控件简单介绍 一.Date Picker控件 1.简单介绍: Date Picker显示时间的控件 有默认宽高,不用设置数据源和代理 如何 ...

  8. yii2-user

    https://github.com/dektrium/yii2-user 安装 : composer require "dektrium/yii2-user:0.9.*@dev" ...

  9. log4net.config 单独文件

    使用的命名空间下添加 [assembly: log4net.Config.DOMConfigurator(ConfigFile = "log4net.config", Watch ...

  10. hdu 1051 (greedy algorithm, how a little modification turn 15ms to 0ms) 分类: hdoj 2015-06-18 12:54 29人阅读 评论(0) 收藏

    the 2 version are essentially the same, except version 2 search from the larger end, which reduce th ...