Nginxは使用するEchoモジュールを追加します

Nginxは使用するEchoモジュールを追加します

nginxの元のインストールに基づく新しいEchoモジュールは、再解凍して、元のバージョンのNginxソースパッケージにコンパイルする必要がありますが、再インストールする必要はありません。

nginxのインストールは参照できます:
ここをクリック

Echoモジュールソースパッケージのダウンロードリンク:

https://github.com/openresty/echo-nginx-module

Nginxでコンパイルされたモジュールを表示します。

/ usr / local / nginx / sbin / nginx -V
–prefix = / usr / local / nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module

[root@VM-0-6-centos mnt]# cd nginx-1.18.0/
[root@VM-0-6-centos nginx-1.18.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module
[root@VM-0-6-centos nginx-1.18.0]#

Echoモジュールをインストールします。

unzip echo-nginx-module-master.zip

EchoモジュールをNginxに動的に追加します。

./configure --prefix = / usr / local / nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module --add-module = / mnt / echo-nginx-module-master

[root@VM-0-6-centos mnt]# cd nginx-1.18.0/
[root@VM-0-6-centos nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module --add-module=/mnt/echo-nginx-module-master

Nginxを再コンパイルします:

make、これにはインストールステートメントを使用せず、コンパイルしてメインプログラムを生成し、既存のメインプログラムを置き換えます。

[root@VM-0-6-centos nginx-1.18.0]# make

ここでEchoモジュールを正常に追加します

[root@VM-0-6-centos objs]# ./nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module --add-module=/mnt/echo-nginx-module-master
[root@VM-0-6-centos objs]# pwd
/mnt/nginx-1.18.0/objs

新しいNginxプログラムを有効にします。

pkill nginx
cp /mnt/nginx-1.18.0/objs/nginx /usr/local/nginx/sbin/

練習:

[root@VM-0-6-centos nginx-1.18.0]# cp /mnt/nginx-1.18.0/objs/nginx /usr/local/nginx/sbin/
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y
[root@VM-0-6-centos nginx-1.18.0]# 

正常にコピーされました

[root@VM-0-6-centos nginx-1.18.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module --add-module=/mnt/echo-nginx-module-master
[root@VM-0-6-centos nginx-1.18.0]# 

#Restart Nginx:

/usr/local/nginx/sbin/nginx 

エコーモジュールテスト:

vim nginx.conf、編集サーバー

location /test {
	echo "user123";
}

カールテスト

curl http://106.52.36.65/echo1

エコー出力組み込み変数:

location /test {
	echo $remote_addr;
}

変数の定義と出力:

location /test {
	set $name user123;
	echo $name;
}

複数の場所を非同期に実行します。

location /echo1 {
    echo_sleep 1;
    echo '111';
}

location /echo2 {
    echo_sleep 1;
    echo '222';
}

location /main {
      echo_reset_timer;
 
      echo_location_async /echo1;
      echo_location_async /echo2;
 
      echo "took $echo_timer_elapsed sec for total.";
}

複数の場所の同時実行:

location /echo1 {
    echo_sleep 1;
    echo '111';
}

location /echo2 {
    echo_sleep 2;
    echo '222';
}

location /main {
      echo_reset_timer;
 
      echo_location /echo1;
      echo_location /echo2;
 
      echo "took $echo_timer_elapsed sec for total.";
}

echo_duplicateは、出力を複数回繰り返します。

location /echo3 {
    echo_duplicate 10 "hello ";
}

おすすめ

転載: blog.csdn.net/weixin_39218464/article/details/112693439