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. java mail发送邮件

    最近做了自动发送邮件功能,带附件的:需要的jar包有

  2. AngularJS事件绑定的使用详解

    本文和大家分享的主要是AngularJS中事件绑定相关知识点,希望通过本文的分享,对大家学习和使用AngularJS有所帮助. 1.绑定事件:表达式.事件方法名: 2.绑定点击事件实例:显示.隐藏页面 ...

  3. 各种效果的tab选项卡

    ;(function($){ $.fn.tabso=function( options ){ var opts=$.extend({},$.fn.tabso.defaults,options ); r ...

  4. 树(二)——二叉树

    目录 本章主要讲解内容为: 树的非递归遍历算法,两种版本 树的扩展前缀以及前缀中缀构建方法 源码 btree.cpp btree.h 基础知识 一.定义 二叉树的递归定义:二叉树是每个结点最多含有两棵 ...

  5. 移动端web之像素基础

    px:css pixels逻辑像素,浏览器使用的抽象单位 dp,pt :device independent pixels 设备无关像素 dpr:devicePixelRatio 设备像素缩放比 计算 ...

  6. bzoj 2763: [JLOI2011]飞行路线

    #include<cstdio> #include<cstring> #include<iostream> #include<queue> #defin ...

  7. UISlider

    UISlider是iOS中的滑块控件 通常⽤于控制视频播放进度,控制⾳量等. 它继承于UIControl,滑块提供了⼀系列连续的值,滑块停 在不同的位置,获取到滑块上的值也不同.   minimumV ...

  8. Rhel6-mpich2 hpc集群配置文档

    系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.121 server21.example.com 192.168.12 ...

  9. 1-5Tomcat 目录结构 和 web项目目录结构

    对应我的安装路径: web项目目录结构

  10. Android M新特性之APP Link

    The Android M Developer Preview introduces support for App Links, which improves upon existing link ...