安装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. [转]SQL Collation冲突解决 临时表

    本文转自:http://ju.outofmemory.cn/entry/191163 问题描述 在SQL Server中使用一些复杂的存储过程时,我们需要借用临时表来完成一些逻辑的处理,例如:数据的临 ...

  2. MVC应用程序使用Entity Framework

    创建空的MVC应用程序,为了想使用Entity Framework的类库,发现即无法正常引用.如下图,Insus.NET已经明确引了System.Data.Entity(下图Highlight的代码) ...

  3. 一个div中有一个a标签,点击a标签的时候不进入div的点击事件

    //阻止冒泡上层clickevent.stopPropagation();

  4. 一卡通大冒险(hdu2512)

    一卡通大冒险 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  5. C#进行数据筛选(二)

    这里介绍LINQ+Lambda表达式进行数据筛选的方式 这里是第一种方式,还是使用了if条件语句去判断,根据选择的条件去筛选出我所需要的数据 public GxAnaly SelectDay(stri ...

  6. apache2.4.33伪静态配置入门教程(1)

    伪静态: 把动态网页的请求方式伪装成静态网页 要使用伪静态技术,要在httpd.conf中启用伪静态模块: LoadModule rewrite_module modules/mod_rewrite. ...

  7. Codeforces35E(扫描线)

    E. Parade time limit per test:2 seconds memory limit per test:64 megabytes input:input.txt output:ou ...

  8. SDN架构

    一:网络设备(Network Devices) 二:南向接口(Southbound Interface) 三:控制器(Controllers) 四:北向接口(Northbound Interface) ...

  9. Software-Defined Networking A Comprehensive Survey --阅读_day1

    The Internet has led to the creation of a digital society, where (almost) everything is connected an ...

  10. 在微信小程序中引入 Iconfont 阿里巴巴图标库

    小程序的代码包不能超过4M,为了压缩代码包的大小,可以通过第三方链接引入图标资源 Iconfont 无疑是最常用的第三方图标库,这里介绍一下在微信小程序引入 Iconfont 的方法 一.下载图标 首 ...