zoukankan      html  css  js  c++  java
  • 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
    /
    
  • 相关阅读:
    shared_ptr weak_ptr boost 内存管理
    _vimrc win7 gvim
    qt 拖放
    数学小魔术 斐波那契数列
    qt4 程序 移植到 qt5
    (转)字符串匹配算法总结
    c++11
    BM 字符串匹配
    编译qt5 demo
    c++ 类库 学习资源
  • 原文地址:https://www.cnblogs.com/cuchadanfan/p/7905394.html
Copyright © 2011-2022 走看看