openresty / echo-nginx-module

An Nginx module for bringing the power of "echo", "sleep", "time" and more to Nginx's config file
http://wiki.nginx.org/NginxHttpEchoModule
BSD 2-Clause "Simplified" License
1.17k stars 254 forks source link

echo_before/after_body not work with rewrite directive #62

Closed ambjlon closed 8 years ago

ambjlon commented 8 years ago
server {
listen 8001;
location ~ /abc/say$ {
     echo "world";
}
location = /xyz/speak {
     echo_before_body "hello";
     rewrite ^/xyz/speak$ /abc/say last;
}
}

curl "http://www.example.com/xyz/speak" gets the output: world Why is not the output like below: hello world

However, I found that the "proxy_pass" works well with echo_before_body.

agentzh commented 8 years ago

Again, you need to understand the running phases of nginx directives. rewrite always runs before echo_before_body, no matter how they appear in the nginx.conf file. See my suggestions in #63.