http-captcha #

Generates CAPTCHA images in nginx and checks the answer that a visitor types in. Use it to put a challenge in front of login, sign-up or comment forms. Pass the typed answer to captcha_answer, and the module sets $captcha_valid.

Source: upstream source

Directives

captcha #

syntax: captcha;  ·  default: ——  ·  context: location

Enables generation of captcha image. Only GET requests are accepted; any other method, including HEAD, gets a 405 response with Allow: GET. The image is sent with Cache-Control: no-store; the expires directive replaces it if set.

captcha_answer #

syntax: captcha_answer string;  ·  default: ——  ·  context: http, server, location

Sets the user's answer to check with $captcha_valid. The value can contain variables.

captcha_case #

syntax: captcha_case on | off;  ·  default: on  ·  context: http, server, location

Enables/disables ignoring captcha case.

captcha_charset #

syntax: captcha_charset string;  ·  default: abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789  ·  context: http, server, location

Sets characters used in captcha text. The string must be valid UTF-8, and captcha_length counts characters, not bytes. captcha_case folds only ASCII letters, so for other scripts (e.g. Cyrillic) use letters of a single case. The font must contain glyphs for all characters.

captcha_csrf #

syntax: captcha_csrf string;  ·  default: csrf  ·  context: http, server, location

Sets name of csrf var of captcha.

captcha_expire #

syntax: captcha_expire seconds;  ·  default: 300  ·  context: http, server, location

Sets seconds before expiring captcha, from 0 to 2147483647.

captcha_flags #

syntax: captcha_flags string;  ·  default: Path=/; HttpOnly; SameSite=Lax  ·  context: http, server, location

Sets attributes appended to the captcha cookie after Max-Age. The value can contain variables. Add Secure when the site is served over HTTPS (including behind a TLS-terminating proxy). An empty string adds no attributes.

captcha_font #

syntax: captcha_font string;  ·  default: /usr/local/share/fonts/NimbusSans-Regular.ttf  ·  context: http, server, location

Sets font of captcha text. A value containing / is a font file path; anything else is a fontconfig pattern, e.g. "DejaVu Sans:bold". If gd cannot use the file, the error is logged and the text is drawn with fontconfig's sans instead.

captcha_height #

syntax: captcha_height pixels;  ·  default: 30  ·  context: http, server, location

Sets height of captcha image, from 1 to 65535.

captcha_length #

syntax: captcha_length characters;  ·  default: 4  ·  context: http, server, location

Sets length of captcha text, from 1 to 65535 and not more than captcha_width.

captcha_level #

syntax: captcha_level number;  ·  default: -1  ·  context: http, server, location

Sets the PNG compression level, from 0 (none) to 9 (best); -1 uses zlib's default compression. Other values are rejected.

captcha_line #

syntax: captcha_line number;  ·  default: 10  ·  context: http, server, location

Sets number of random noise lines drawn over the captcha image.

captcha_name #

syntax: captcha_name string;  ·  default: Captcha  ·  context: http, server, location

Sets name of captcha cookie.

captcha_secret #

syntax: captcha_secret string;  ·  default: ——  ·  context: http, server, location

Sets secret of captcha. Mandatory: a location that enables captcha; without a captcha_secret set anywhere in its config hierarchy will return a 500 for every request.

captcha_size #

syntax: captcha_size pixels;  ·  default: 20  ·  context: http, server, location

Sets size of captcha font, from 1 to 65535 and not more than captcha_height.

captcha_star #

syntax: captcha_star number;  ·  default: 100  ·  context: http, server, location

Sets number of random noise stars ("*") drawn over the captcha image.

captcha_width #

syntax: captcha_width pixels;  ·  default: 130  ·  context: http, server, location

Sets width of captcha image, from 1 to 65535.

Example

    location = /captcha {
        captcha;
        captcha_secret secret;
        captcha_name MyCaptcha;
        captcha_expire 123;
    }

↑ back to index