nginx驗證碼模塊

ngx_http_captcha_module

地址:https://github.com/dengqiang2015/ngx_http_captcha_modulenginx

說明:

此nginx模塊可直接生成驗證碼和驗證驗證碼,可在nginx配置中自定義驗證碼大小、長度、字體、過時時間等。此項目無需版權,可自由下載使用或二次開發。git

安裝方法:

1. $ cp ngx_http_captcha_module.c /usr/local/src/nginx-1.14.0/src/http/modules/github

2. cd /usr/local/src/nginx-1.14.0redis

3. $ vim auto/modulesvim

添加代碼字體

if :; then
    ngx_module_name=ngx_http_captcha_module
    ngx_module_incs=
    ngx_module_deps=
    ngx_module_srcs=src/http/modules/ngx_http_captcha_module.c
    ngx_module_libs=
    ngx_module_link=YES
. auto/module 

fi

4. $ ./configure --with-debugspa

5. $ vim objs/Makefiledebug

找到code

objs/src/http/modules/ngx_http_captcha_module.o:        $(CORE_DEPS) $(HTTP_DEPS) \
        src/http/modules/ngx_http_captcha_module.c
        $(CC) -c -g $(CFLAGS) $(CORE_INCS) $(HTTP_INCS) \
                -o objs/src/http/modules/ngx_http_captcha_module.o \
                src/http/modules/ngx_http_captcha_module.c

改成圖片

objs/src/http/modules/ngx_http_captcha_module.o:        $(CORE_DEPS) $(HTTP_DEPS) \
        src/http/modules/ngx_http_captcha_module.c
        $(CC) -c -g $(CFLAGS) $(CORE_INCS) $(HTTP_INCS) \
                -I /usr/include -I /usr/local/include \
                -L /usr/lib/ -L /usr/local/lib/ -lgd -lhiredis \
                -o objs/src/http/modules/ngx_http_captcha_module.o \
                src/http/modules/ngx_http_captcha_module.c

找到

-ldl -lrt -lpthread -lcrypt -lpcre -lz \

改成

-ldl -lrt -lpthread -lcrypt -lpcre -lz -lgd -lhiredis \

6. $ make && make install

nginx配置

location /captcha_img {
        captcha_redis_conf 127.0.0.1 6379;    #redis配置,默認127.0.0.1 6379
        captcha_init;                         #驗證碼初始化
        captcha_width 130;                    #驗證碼寬度,默認130像素
        captcha_height 30;                    #驗證碼高度,默認30像素
        captcha_length 4;                     #驗證碼長度,默認4,最大長度6
        captcha_font /data/font/elephant.ttf; #字體庫
        captcha_expire 3600;                  #過時時間, 默認3600秒
        captcha_output;                       #輸出圖像
    }
location /captcha_auth {
        captcha_redis_conf 127.0.0.1 6379; #redis配置,默認127.0.0.1 6379
        captcha_auth; #驗證
}

重啓nginx
訪問http://xxx/captcha_img顯示驗證碼圖片

訪問http://xxx/captcha_auth?captcha_code=1234

captcha_code=1234爲用戶輸入的驗證碼參數,用get請求方式

相關文章
相關標籤/搜索