nginx报错 [emerg] unknown directive "echo"
问题现象:
#nginx -t
nginx: [emerg] unknown directive "echo" in /apps/nginx-1.18.0/conf.d/p.conf:24
nginx: configuration file /apps/nginx-1.18.0/conf/nginx.conf test failed
原因缺少echo 模块,需重新编译解决
#cd /apps/nginx-1.18.0
#yum -y install git
#git clone https://github.com/openresty/echo-nginx-module.git
#./configure --prefix=/apps/nginx-1.18.0 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/apps/nginx-1.18.0/echo-nginx-module
#make -j 2 && make install
#nginx -t
nginx: the configuration file /apps/nginx-1.18.0/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx-1.18.0/conf/nginx.conf test is successful
测试验证
#systemctl daemon-reload
#systemctl restart nginx
#curl mp.weirui.vip/main -L
hello world,main-->
10.0.0.117
sub1
sub2
took 2.011 sec for total.
配置如下
#cat /apps/nginx-1.18.0/conf.d/p.conf
server {
listen 80;
root /apps/nginx-1.18.0/html;
server_name mp.weirui.vip;
access_log logs/vip-access.log;
error_log logs/vip-error.log;
location / {
stub_status;
index txt json doc index.html index.htm;
}
location /main {
index index.html;
default_type text/html;
echo "hello world,main-->";
echo $remote_addr ;
echo_reset_timer;
echo_location /sub1;
echo_location /sub2;
echo "took $echo_timer_elapsed sec for total.";
}
location /sub1 {
echo_sleep 1;
echo sub1;
}
location /sub2 {
echo_sleep 1;
echo sub2;
}
}