sudo apt install libperl-dev libgeoip-dev libgd-dev libhiredis-dev unzip gcc make libpcre3-dev zlib1g-dev redis
wget https://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvf nginx-1.18.0.tar.gz
mv nginx-1.18.0 /usr/local/src/
cd /usr/local/src/nginx-1.18.0
git clone https://github.com/subhransusekhar/nginx-http-captcha.git
./configure --add-module=nginx-http-captcha
vi objs/Makefile
search for
-ldl -lrt -lpthread -lcrypt -lpcre -lz \
replace with
-ldl -lrt -lpthread -lcrypt -lpcre -lz -lgd -lhiredis \
make && make install
location /captcha_img/ { #captcha_redis_conf 127.0.0.1 6379; #redis configuration, default 127.0.0.1 6379 captcha_init; # verification code initialization captcha_width 130; #Captcha width, default 130 pixels captcha_height 30; #Captcha height, default 30 pixels captcha_length 4; #Verification code length, default 4, maximum length 6 captcha_font /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf; #font library captcha_expire 3600; #Expire time, default 3600 seconds captcha_output; #output image }
location /captcha_auth/ { #captcha_redis_conf 127.0.0.1 6379; #redis configuration, default 127.0.0.1 6379 captcha_auth; #verify }
validate the configuration file
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
Visit http://xxx/captcha_img/ to display the captcha image
Visit http://xxx/captcha_auth/?captcha_code=1234
captcha_code=1234 is the verification code parameter input by the user