others-How to rebuild openrestyfrom source code with debug enabled?

1. Purpose

In this post, I would demo how to build or rebuild openresty with debug enabled.


2. The problem and solution

2.1 The problem

The configuration that cause the problem is as follows:

events {
    worker_connections  1024;
    debug_connection 127.0.0.1;
}

I want to enable debug on some connection to openresty, but when I add debug_connection directive in nginx.conf, I got this error:

➜  1.19.9.1_2 openresty -t
nginx: [warn] "debug_connection" is ignored, you need to rebuild nginx using --with-debug option to enable it in /usr/local/etc/openresty/nginx.conf:13
nginx: the configuration file /usr/local/etc/openresty/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/openresty/nginx.conf test is successful

2.2 The solution

Because I installed openresty from binary, we should uninstall it at first ,then rebuild it from source.

brew uninstall openresty/brew/openresty

Then download the source code of openresty as follows:

wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
tar zxvf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1

Install openresty dependencies:

brew install pcre openssl

Then compile openresty from source:

./configure \
   --with-cc-opt="-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/" \
   --with-ld-opt="-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/" \
   -j8 --with-debug

The key option for debug is: --with-debug,then openresty would has debug capability.

Now rebuild openresty:

make 
sudo make install

At last, we should set environment variables for openresty:

export OPENRESTY_HOME=/usr/local/openresty
export PATH=$OPENRESTY_HOME/bin:$OPENRESTY_HOME/nginx/sbin:$PATH



3. Summary

In this post, I demonstrated how to rebuild openresty from source with debug enabled . That’s it, thanks for your reading.