日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx安装echo模块

發布時間:2025/3/21 Nginx 60 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx安装echo模块 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

echo-nginx-module 模塊可以在Nginx中用來輸出一些信息,可以用來實現簡單接口或者排錯。

項目地址:https://github.com/openresty/echo-nginx-module

獲取Nginx源碼

因為需要編譯模塊,需要有Nginx源碼。

如果已安裝Nginx,需要查看當前安裝版本的編譯參數:

$ /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.12.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module

其中configure arguments這個參數是非常重要的,我們在后面安裝Lua模塊的時候,需要以這個為基礎,增加新的參數。

如果還沒有安裝Nginx,上面可以忽略。

Nginx下載頁面:http://nginx.org/en/download.html

這里我們以 nginx/1.12.2 為例。需要獲取源碼:

$ cd /opt/ $ wget http://nginx.org/download/nginx-1.12.2.tar.gz $ tar -zxvf nginx-1.12.2.tar.gz

安裝取echo-nginx-module

獲取echo-nginx-module

我們下載最新穩定版(截止到2018-12-23),并解壓,不用安裝:

$ cd /opt $ wget https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz $ tar zxvf v0.61.tar.gz

編譯Nginx

Nginx編譯參數配置:

$ cd /opt/nginx-1.12.2/ $ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --add-module=/opt/echo-nginx-module-0.61

這里因為已經安裝了Nginx,所以這里的參數是從Nginx -V的輸出里獲取的,并追加了新的參數:

--add-module=/opt/echo-nginx-module-0.61

運行上面的./configure后進行編譯安裝:

$ make -j2 $ make install

make install后,會覆蓋之前安裝的Nginx。

測試echo模塊

在/usr/local/nginx/conf/nginx.conf中server代碼塊里加入如下代碼:

location /hello { default_type 'text/plain';return 200 'hello!'; }location /hello_echo { default_type 'text/plain'; echo "hello, echo!"; }

注意:重新編譯 Nginx 二進制,Nginx 需要停止重啟。而普通配置更新則 reload 即可:

$ kill -QUIT `cat /usr/local/nginx/logs/nginx.pid` && /usr/local/nginx/sbin/nginx

如果支持service nginx restart,則可以這樣重新啟動:

$ service nginx restart && /usr/local/nginx/sbin/nginx -s reload

然后curl測試:

$ curl http://127.0.0.1/hello hello!$ curl http://127.0.0.1/hello_echo hello, echo!

當然, echo-nginx-module 模塊不僅僅是提供echo這么簡單的指令,還有其它的指令,詳見:https://github.com/openresty/echo-nginx-module#content-handler-directives

編譯動態模塊

echo-nginx-module 支持以動態模塊方式加載,詳見:https://github.com/openresty/echo-nginx-module#installation 。Nginx版本需要 >=1.9.11 。

$ cd /opt/nginx-1.12.2/ $ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --add-dynamic-module=/opt/echo-nginx-module-0.61$ make -j2 $ make install

相比靜態編譯,參數--add-module改成了--add-dynamic-module。

編譯成功后,會把模塊安裝在nginx/modules/目錄。查看:

$ ls /usr/local/nginx/modules/ ngx_http_echo_module.so

接下來我們需要在nginx.conf配置中加入以下兩行,實現動態調用模塊:

load_module /usr/local/nginx/modules/ngx_http_echo_module.so;

注意:load_module指令不能放在 http{} 里面:

worker_processes 1;load_module xxx;#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024; }http {}

接下來可以按上面的 測試echo模塊 小節測試。唯一不同的是無需使用kill -QUIT退出Nginx,直接使用nginx -s reload熱重啟就行了。

參考

1、Nginx安裝Nginx-echo模塊 - chen2013 - 博客園
http://www.cnblogs.com/chenjianxiang/p/8489055.html
2、openresty/echo-nginx-module
https://github.com/openresty/echo-nginx-module#installation
3、Nginx編譯安裝Lua - 飛鴻影~ - 博客園
https://www.cnblogs.com/52fhy/p/10164553.html

總結

以上是生活随笔為你收集整理的Nginx安装echo模块的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。