安装echo模块

下载模块

# pwd
/root
# git clone https://github.com/openresty/echo-nginx-module

重新编译

先查看版本,然后根据需要看是否需要升级nginx版本,这里是按原先的版本来添加echo模块。

# /opt/nginx/sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-http_mp4_module --with-http_spdy_module --with-http_flv_module --with-http_stub_status_module --with-pcre
# wget http://nginx.org/download/nginx-1.6.3.tar.gz
# tar -xf nginx-1.6.3.tar.gz
# cd nginx-1.6.3
# ./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_mp4_module --with-http_spdy_module --with-http_flv_module --with-http_stub_status_module --with-pcre --add-module=/root/echo-nginx-module/
# make

注意不要进行install 操作,为了避免覆盖正在使用的nginx程序。

# mv /opt/nginx/sbin/nginx /opt/nginx/sbin/nginx.old
# cp objs/nginx /opt/nginx/sbin/
# cd /opt/nginx/sbin/
# ./nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-http_mp4_module --with-http_spdy_module --with-http_flv_module --with-http_stub_status_module --with-pcre --add-module=/root/echo-nginx-module/
# kill -USR2 `cat /opt/nginx/logs/nginx.pid`
# kill -QUIT `cat /opt/nginx/logs/nginx.pid.oldbin`

location 配置

nginx 配置文件

server {
server_name www.example.com;
listen 80;
access_log /data/log/nginx/www.example.com.log;
root /opt/web/www.example.com;
location / {
echo "/";
}
location = /{
echo "=/";
}
location = /nginx {
echo "=/nginx";
}
location /nginx/ {
echo "/nginx/";
} location ~ \.(gif|jpg|png|js|css)$ {
echo "small-gif/jpg/png";
}
location ~* \.png$ {
echo "all-png";
}
location ^~ /static/ {
echo "static";
}
}

下面需要做好本地hosts的域名解析,这里不做演示。

测试如下

# tree /opt/web/www.example.com/
/opt/web/www.example.com/
└── index.html 0 directories, 1 file
# curl http://www.example.com
=/
# curl http://www.example.com/nginx
=/nginx
# curl http://www.example.com/nginx/index.html
/nginx
# curl http://www.example.com/yyf/pangtouyu.png
small-gif/jpg/png
# curl http://www.example.com/yyf/pangtouyu.PNG
all-png
# curl http://www.example.com/static/pangtouyu.png
static
# curl http://www.example.com/static/pangtouyu.PNG
static
# curl http://www.example.com/nginx/a.txt
/

nginx之location.md的更多相关文章

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

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

  2. Nginx之location 匹配规则详解

    有些童鞋的误区 1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通, ...

  3. nginx 中location和root

    nginx 中location和root,你确定真的明白他们关系? 2016-01-17 14:48 3774人阅读 评论(1) 收藏 举报  分类: linux(17)  版权声明:本文为博主原创文 ...

  4. Nginx 的 Location 配置指令块

    最近一段时间在学习 Nginx ,以前一直对 Nginx 的 Location 配置很头大,最近终于弄出点眉目.总结如下:nginx 配置文件,自下到上分为三种层次分明的结构: |    http b ...

  5. 快速掌握Nginx(二) —— Nginx的Location和Rewrite

    1 location详解 1.location匹配规则 Nginx中location的作用是根据Url来决定怎么处理用户请求(转发请求给其他服务器处理或者查找本地文件进行处理).location支持正 ...

  6. nginx之location的匹配规则

    nginx之location的匹配规则 一.语法规则 location [=|~|~*|^~] /uri/ { - } 符号 含义 = 开头表示精确匹配 ^~ 开头表示 uri 以某个常规字符串开头 ...

  7. Nginx的location匹配规则

    一 Nginx的location语法 location [=|~|~*|^~] /uri/ { … } =         严格匹配.如果请求匹配这个location,那么将停止搜索并立即处理此请求 ...

  8. nginx:location指令中的正则表达式

    nginx:location指令中的正则表达式 uri匹配步骤 官网说明https://docs.nginx.com/nginx/admin-guide/web-server/web-server/ ...

  9. Nginx的location配置规则梳理

    Nginx几乎是当下绝大多数公司在用的web应用服务,熟悉Nginx的配置,对于我们日常的运维工作是至关重要的,下面就Nginx的location配置进行梳理: 1)location匹配的是nginx ...

随机推荐

  1. nodejs 的序列化与反序列化

    1.序列化 stringify函数的作用就是序列化对象,也就是说将对象类型转换成一个字符串类型(默认的分割符("&")和分配符("=")),先介绍它的基 ...

  2. 关于 luv_letters

    luv_letters是一枚现高二文化课菜鸡,是一枚临汾一中联赛oier(我太菜了),也是一名Cher. (好像没有好的地方 真名不提跟某个当红女明星一样(正经汉子不女装 话说当初选择竞赛科目的时候( ...

  3. 一.JDK版本切换批处理脚本

    我们平时在window上做开发的时候,可能需要同时开发两个甚至多个项目,有时不同的项目对JDK的版本要求有区别,这时候我们可能会在一台电脑上安装多个版本的JDK,如下图所示:

  4. oracle逐步学习总结之oracle数字函数和日期函数(基础四)

    原创作品,转自请注明出处:https://www.cnblogs.com/sunshine5683/p/10140716.html 继上篇总结,继续进行总结: 以下下数字函数: 1.abs(n):返回 ...

  5. 深入浅出Mybatis技术原理与实战(杨开振)(带详细书签) PDF 下载 高清 完整版+源码

    (杨开振) 源码 IDE eclipse 建表语句也在里面 电子书+源码地址

  6. 获取和添加URL地址栏参数

    URL地址(添加参数:传参) js写法: //1.window.location.href var a ="1018802,8" var b ="1" wind ...

  7. python中的赋值与深浅拷贝的区别

    import copy lt = [1, 2, [3, 4]] # 赋值会增加一个引用,访问的都是同一数据 # lt2 = lt # 浅拷贝:只拷贝对象本身,里面的元素只会增加一个引用 lt2 = l ...

  8. 关于animation的一些简单基础和使用方法记载

    第一次写博客,只是单纯的想把我自己的一些心得和使用过的css3的animation的一些方法记录和总结,方便下次使用,我写的这些都是刚入门适合做一些简单的动画动作,过于复杂的还有待发掘或者使用别的方法 ...

  9. CentOS7添加入windows2008的AD域

    采用域控对用户权限进行限制的时候,经常会出现需要将linux加入windows域,毕竟windows的AD域超级强大.用户名可以由windows进行统一管理,方便办公使用.下面简单介绍如何进行配置. ...

  10. Nginx的location剖析

    1.location的作用: location指令的作用是根据用户的请求的URL来执行不同的应用 2.location的语法: location [ = | ~ | ~* | ^~ ] uri { . ...