ACME#

Provides automatic certificate retrieval using the ACME protocol.

When building from the source code, the module isn't built by default; it must be enabled with the build option --with-http_acme_module. In packages and images from our repositories, the module is included in the build.

Configuration Example#

Examples of configuration and setup instructions can be found in the ACME Configuration section.

Directives#

acme#

Syntax

acme name;

Default

Context

server

For all domains specified in the server_name directives in all server blocks that reference the ACME client with the given name, a single certificate will be obtained; if the server_name configuration changes, the certificate will be renewed to reflect the changes.

Each time Angie starts, new certificates are requested for all domains that are missing a valid certificate. Possible reasons include certificate expiration, missing or unreadable files, and changes in certificate settings.

Note

Currently, domains specified with regular expressions are not supported and will be skipped.

Wildcard domains are supported only with challenge=dns in acme_client.

This directive can be specified multiple times to load certificates of different types, for example RSA and ECDSA:

server {

    listen 443 ssl;
    server_name example.com www.example.com;

    ssl_certificate $acme_cert_rsa;
    ssl_certificate_key $acme_cert_key_rsa;

    ssl_certificate $acme_cert_ecdsa;
    ssl_certificate_key $acme_cert_key_ecdsa;

    acme rsa;
    acme ecdsa;
}

acme_client#

Syntax

acme_client name uri [enabled=on | off] [key_type=type] [key_bits=number] [email=email] [max_cert_size=number] [renew_before_expiry=time] [renew_on_load] [retry_after_error=off|time] [challenge=dns | http] [account_key=file];

Default

Context

http

Defines an ACME client with a globally unique name. It must be valid for a directory, is a string with variables, and will be used case-insensitively.

Tip

The client name specified here identifies it in the Angie configuration, allowing you to match acme_client, acme directives, and module variables that use this name; don't confuse it with your domain or server name.

The second mandatory parameter is the uri of the ACME directory. For example, the Let's Encrypt ACME directory URI is specified as https://acme-v02.api.letsencrypt.org/directory.

Note

The ACME module adds a named location @acme to the client context, which can be used to configure requests to the ACME directory; by default, this location contains a proxy_pass directive with the directory uri, to which other settings from the Proxy module can be added.

For this directive to work, a resolver must be configured in the same context.

Note

For testing purposes, certificate authorities usually provide separate staging environments. For example, the Let's Encrypt staging environment is https://acme-staging-v02.api.letsencrypt.org/directory.

enabled

Enables or disables certificate renewal for the client; this is useful, for example, for temporarily suspending without removing the client from the configuration.

Default: on.

key_type

The type of private key algorithm for the certificate. Valid values: rsa, ecdsa.

Default: ecdsa.

key_bits

Number of bits in the certificate key. Default: 256 for ecdsa, 2048 for rsa.

email

Optional email address for feedback; used when creating an account on the CA server.

max_cert_size

Specifies the maximum allowed size of a new certificate file in bytes to reserve space for the new certificate in shared memory; the more domains the certificate is requested for, the more space is required.

If a certificate already exists at startup but its size exceeds the max_cert_size value, the max_cert_size value is dynamically increased to match the size of the existing certificate file.

If the size of a certificate obtained during renewal exceeds max_cert_size, the renewal process will fail with an error.

Default: 8192.

renew_before_expiry

Time before certificate expiration when renewal should begin.

Default: 30d.

renew_on_load

Specifies that the certificate should be forcibly renewed each time the configuration is loaded.

retry_after_error

Time to wait before retrying if certificate retrieval failed. If set to off, the client will not retry to obtain the certificate after an error.

Default: 2h.

challenge

Specifies the verification type for the ACME client. Valid values: dns, http.

Default: http.

account_key

Specifies the full path to a file containing a key in PEM format. This is useful if you want to use an existing account key instead of automatic generation, or if you need to use one key for multiple ACME clients.

Supported key types:

  • RSA keys with lengths that are multiples of 8, ranging from 2048 to 8192 bits.

  • ECDSA keys with lengths of 256, 384, or 521 bits.

When specifying the account_key parameter, ensure that the key file actually exists. If the file is missing, Angie will attempt to create it at the specified path.

Note that keys for ACME clients are created in the order the corresponding clients are mentioned in the configuration in acme_client, acme, or acme_hook directives. Therefore, if one client should use a key created for another, that other client must appear earlier in the configuration.

Additionally, keys are only created for clients that have the enabled=on parameter set.

acme_client_path#

Syntax

acme_client_path path;

Default

Context

http

Overrides the path to the directory for storing certificates and keys, specified at build time with the build option --http-acme-client-path.

acme_dns_port#

Syntax

acme_dns_port port | ip[:port] | [ip6][:port];

Default

acme_dns_port 53;

Context

http

Specifies the port that the module uses to handle DNS queries from the ACME server over UDP. The port number must be in the range from 1 to 65535.

Specifying an IP address along with an optional port is also supported. Both IPv4 addresses in the form ip:port and IPv6 addresses in the form [ip6]:port can be used:

acme_dns_port 8053;
acme_dns_port 127.0.0.1;
acme_dns_port [::1];

To use port number 1024 or lower, Angie must run with superuser privileges.

acme_hook#

Syntax

acme_hook name [uri];

Default

Context

location

The directive links the server to the specified ACME client. Handler (hook) calls implemented by an external service are made through the location context where it is located.

name

Specifies the corresponding ACME client.

uri

A string with variables; specifies the request string for handler calls.

Default: /.

For example, the following configuration passes the values of hook variables to a FastCGI application through the request string:

acme_hook example uri=/acme_hook/$acme_hook_name?domain=$acme_hook_domain&key=$acme_hook_keyauth;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_pass ...;

Built-in Variables#

$acme_cert_<name>#

Contents of the last certificate file (if any) obtained by the client with this name.

$acme_cert_key_<name>#

Contents of the certificate key file used by the client with this name.

Important

The certificate file is available only if the ACME client has obtained at least one certificate, but the key file is available immediately after startup.

$acme_hook_challenge#

The verification type. Possible values: dns, http.

$acme_hook_client#

The name of the ACME client initiating the request.

$acme_hook_domain#

The domain being verified. If it is a wildcard domain, it will be passed without the *. prefix.

$acme_hook_keyauth#

The authorization string:

  • For DNS verification, it is used as the value of the TXT record, whose name is formed as _acme-challenge. + $acme_hook_domain + ..

  • For HTTP verification, this string must be used as the content of the response requested by the ACME server.

$acme_hook_name#

The hook name. For different verification types, it may have different values and meanings:

Value

Meaning for DNS verification

Meaning for HTTP verification

add (adding hook)

The corresponding TXT record must be added to the DNS configuration.

A response to the corresponding HTTP request must be prepared.

remove (removing hook)

The TXT record can be removed from the DNS configuration.

This HTTP request is no longer relevant; the previously created file with the authorization string can be removed.

$acme_hook_token#

The verification token. For HTTP verification, it is used as the name of the requested file: /.well-known/acme-challenge/ + $acme_hook_token.