nginx之location.md

Posted ProfiBus

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx之location.md相关的知识,希望对你有一定的参考价值。

安装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的主要内容,如果未能解决你的问题,请参考以下文章

Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error code(代码片段

深刻理解Nginx之基本配置和升级

面向面试编程代码片段之GC

日更第17日: (翻)nginx加固之防御缓冲区溢出攻击

nginx.conf 忽略了 nginx-ingress 配置映射片段

将 nginx rtmp 片段发送到 WebRTC