nginx location匹配顺序及CI框架的nginx配置
Nginx location匹配顺序如下:
- 用前缀字符串定义的location规则对URI进行匹配测试。
- =号定义了精确的前缀字符串匹配,如果发现精确匹配则使用当前规则。否则继续下一步匹配。
- 匹配其它普通字符串,并存储最长匹配。如果匹配以^~开始的规则,则使用当前匹配,否则继续下一步匹配。
- 按顺序对URI进行正则规则匹配,发现匹配后停止并使用当前匹配。若所有正则都不匹配,则使用第3步存储的最长匹配规则。
- ~ 开头表示区分大小写的正则匹配;
- ~* 开头表示不区分大小写的正则匹配
整体匹配优先级 =精确匹配 > ^~前缀匹配 > 正则匹配 > 普通前缀字符串匹配
rewrite块可直接放在server段内,也可置于location段内。请求到达nginx后,URI会进行如下处理:
URI->server rewrite->new URI->location匹配
在location规则匹配过程中若对url进行了重写,则要重新开始规则匹配。若循环10次后仍没有找到真实存在的文件,服务器会返回500错误。
rewrite指令可以附带一个标志位 last/break;对此,我的理解是两者都会终止rewrite的执行,last一般用在server段,break一般用在location内。last执行完还要进行location匹配,而break则不再进行location匹配。
基于CI框架的nginx配置(windows环境):
- #user nobody;
- worker_processes 1;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- #access_log logs/access.log main;
- #开启rewrite日志 测试用 rewrite日志写在error_log里
- rewrite_log on;
- error_log logs/error.log notice;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #tcp_nodelay on;
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- fastcgi_buffer_size 128k;
- fastcgi_buffers 4 128k;
- fastcgi_busy_buffers_size 256k;
- fastcgi_temp_file_write_size 256k;
- #gzip on;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 32k;
- gzip_http_version 1.1;
- gzip_comp_level 2;
- gzip_types text/plain application/x-javascript text/css application/xml;
- gzip_vary on;
- gzip_disable "MSIE [1-6].";
- server_names_hash_bucket_size 128;
- client_max_body_size 100m;
- client_header_buffer_size 256k;
- large_client_header_buffers 4 256k;
- server {
- listen 80;
- server_name citest.com;
- index index.html index.php;
- root "d:/www/ci";
- access_log logs/ciaccess.log main;
- if (!-e $request_filename) {
- rewrite ^/(.*)$ /index.php/$1 last;
- }
- location ~ \.php(.*)$ {
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_param PATH_INFO $fastcgi_path_info;
- fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
- include fastcgi_params;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
- expires 30d;
- }
- location ~ .*\.(js|css)?$ {
- expires 12h;
- }
- }
- #include vhosts.conf;
- }
nginx location匹配顺序及CI框架的nginx配置的更多相关文章
- Nginx location 匹配顺序整理
Nginx location模块整理 具体的Nginx安装就不在这里描述了,这里只是为了对location的描述 Nginx环境 a. 查看当前系统cat /etc/redhat-release [r ...
- Nginx Location匹配顺序
理论部分 文字释义匹配规则如下: 略述: 1.nginx服务器首先在server块的多个location块中搜索是否有标准的uri和请求字符串匹配.如果有多个标准uri可以匹配,就匹配其中匹配度最高的 ...
- nginx location 匹配顺序
location 匹配的原型是这样的:location [=|~|~*|^~|@] /uri/ { … } “=”是精确匹配“@”是命名的location ,在正常的location 匹配中不会使用, ...
- CI框架伪静态化配置
CI框架伪静态化配置 伪静态化,即:去掉入口的index.php, 在url后面加上 .html 后缀 CI默认的rewrite url中是类似这样的,例如你的CI根目录是在/CodeIgniter/ ...
- nginx中location匹配顺序
一.location语法 语法: Syntax: location [ = | ~ | ~* | ^~ ] uri { ... } location @name { ... } Default: - ...
- Nginx location 匹配规则详解
语法规则 location [=|~|~*|^~] /uri/ { … } 模式 含义 location = /uri = 表示精确匹配,只有完全匹配上才能生效 location ^~ /uri ^~ ...
- nginx location匹配规则
谢谢作者的分享精神,原文地址:http://www.nginx.cn/115.html location匹配命令 ~ #波浪线表示执行一个正则匹配,区分大小写~* #表示执行一个正则匹 ...
- 转:nginx location匹配规则
location匹配命令 ~ #波浪线表示执行一个正则匹配,区分大小写~* #表示执行一个正则匹配,不区分大小写^~ #^~表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配 ...
- Nginx Location 匹配
location匹配命令 ~ #波浪线表示执行一个正则匹配,区分大小写~* #表示执行一个正则匹配,不区分大小写^~ #^~表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配 ...
随机推荐
- hdu1242 Rescue bfs+优先队列
直接把Angle的位置作为起点,广度优先搜索即可,这题不是步数最少,而是time最少,就把以time作为衡量标准,加入优先队列,队首就是当前time最少的.遇到Angle的朋友就退出.只需15ms A ...
- mysql无法启动的结果问题解决
mac 上homebrew 安装的mysql,已经用了很长时间都没什么问题,今天 ERROR! The server quit without updating PID file (/usr/loca ...
- layui的几个简单使用(简单弹窗,加载效果,移除加载效果)
1.加载效果和移除加载效果 function layuiLoading(msg){ layui.use(['layer', 'form'], function(){ index = layer.loa ...
- Hbase配置java客户端
1.修改windows配置文件 C:\WINDOWS\system32\drivers\etc\hosts 将远程hbase和zookeeper主机的IP地址加进去 54.0.88.53 H ...
- Django里使用open函数
Django里使用open函数 前言 在Django里使用open函数打开一个文件的时候,常常会遇到路径错误的问题.我在Django APP里写了一个爬虫用于为网站提供数据,但是需要打开文件,也就是在 ...
- javascript对象(简略)
javascript对象有着自有的属性,对象可以从一个称为原型的对象继承属性,对象的方法通常是继承的属性,原型式继承是javascript的核心特征.
- 浏览器通过Scheme协议启动APP中的页面
在APP开发过程中,通过外部浏览器调起APP页面的场景也很普遍使用.下面就介绍一下通过外部H5页面唤起APP中页面的通用方法. 1.首先需要在AndroidMainifest.xml中对你要启动的那个 ...
- APACHE服务器出现No input file specified.的完美解决方案
启用REWRITE的伪静态功能的时候,首页可以访问,而访问内页的时候,就提示:“No input file specified.” 原因在于使用的PHP是fast_cgi模式,而在某些情况下,不能正确 ...
- Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'L
1.错误描述 [ERROR:]2015-06-08 09:49:42,523 [异常拦截] org.hibernate.exception.DataException: error executing ...
- poi 导入导出的api说明(大全)
原文链接:http://www.cnblogs.com/qingruihappy/p/8443101.html poi 导入导出的api说明(大全) 一. POI简介 ApachePOI是Apache ...