Nginx-添加echo模塊

1,Nginx的echo模塊介紹nginx

echo模塊是國人編寫的nginx的第三方模塊,下載官方nginx後須要再下載echo模塊,而且配合nginx編譯安裝,安裝此模塊後能夠在nginx的url訪問中能夠經過echo命令輸出字符到用戶的瀏覽器中,可用於檢測nginx的可訪問性,檢測nginx的配置的正確性等,總之在調試配置nginx環節,echo命令很是有用。git

2,下載echo模塊源碼包:github

# cd /usr/local/src/
# wget https://codeload.github.com/openresty/echo-nginx-module/tar.gz/v0.58  
# tar xvzf v0.58
# ls
  echo-nginx-module-0.58

3,查看Nginx現有編譯的參數:瀏覽器

# /opt/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
built with OpenSSL 1.0.1c 10 May 2012
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1c --add-module=/usr/local/src/echo-nginx-module-0.58

4,重新編譯nginx,添加echo模塊:tomcat

# ./configure --prefix=/opt/nginx --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1c --add-module=/usr/local/src/echo-nginx-module-0.58
#make

注:千萬不要make install,不然就會覆蓋安裝nginx了。bash

5,拷貝可執行文件nginx覆蓋如今的nginx可執行文件app

# /etc/init.d/nginx stop
# cp objs/nginx /opt/nginx/sbin/
# /etc/init.d/nginx start

6,驗證:curl

# cat nginx.conf
#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    #include       conf.d/vhost.conf;
    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;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;  
    server
    {
    listen 80;
    server_name 127.0.0.1;
    location / {
    echo "123";
    }
    access_log logs/tomcat1_access.log;
    }
}

訪問驗證:tcp

# curl 127.0.0.1
123

7,注意:ide

1.echo命令只能放在url請求中,若是放在url請求外,會報錯 若是報[emerg]: "echo" directive is not allowed here in  ,請檢查echo放置的位置

2.一次url請求,echo 只能打印一行,若是有邏輯判斷,且判斷成功,則echo會執行判斷成功裏邊的echo,不然執行最後一句echo(此處不必定正確,在測試中發現是此現象)

3.若是echo後邊有配置return 或者配置 proxy_pass,則echo的輸出會被覆蓋,即瀏覽器沒法看到echo的內容

4.echo的內容不是寫在nginx的配置文件中,而是輸出到瀏覽器中,因此echo的打印字符的查看請在瀏覽器中查看



更多內容,請關注博主我的博客網站:http://www.whysha.com

相關文章
相關標籤/搜索