Skip to content

Commit 0f7bfd5

Browse files
committed
Add documentation for has_certificate and expose shmem_only option.
1 parent eef6d07 commit 0f7bfd5

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,17 @@ auto_ssl:set("http_proxy_options", {
315315
})
316316
```
317317

318-
## `ssl_certificate` Configuration
318+
## API
319+
320+
<a id="ssl_certificate-configuration"></a>
321+
### `ssl_certificate`
322+
*Syntax:* `auto_ssl:ssl_certificate(options)`
319323

320324
The `ssl_certificate` function accepts an optional table of configuration options. These options can be used to customize and control the SSL behavior on a per nginx `server` basis. Some built-in options may control the default behavior of lua-resty-auto-ssl, but any other custom data can be given as options, which will then be passed along to the [`allow_domain`](#allow_domain) and [`request_domain`](#request_domain) callback functions.
321325

322326
Built-in configuration options:
323327

324-
### `generate_certs`
328+
#### `generate_certs`
325329
*Default:* true
326330

327331
This variable can be used to disable generating certs on a per server block location.
@@ -337,7 +341,26 @@ server {
337341
}
338342
```
339343

340-
### Advanced Let's Encrypt Configuration
344+
### `has_certificate`
345+
*Syntax:* `exists = auto_ssl:has_certificate(domain, shmem_only?)`
346+
347+
The `has_certificate` function returns a boolean value for whether or not a certificate exists for the given `domain`. This is first looked up in the local shared memory cache, and then falls back to fetching from storage.
348+
349+
The optional `shmem_only` parameter can be set to true in order to only check the local shared memory cache for the presence of the certificate, and not check the storage engine.
350+
351+
*Example:*
352+
353+
```nginx
354+
rewrite_by_lua_block {
355+
local has_cert = auto_ssl:has_certificate(ngx.var.host)
356+
if has_cert then
357+
local https_uri = "https://" .. ngx.var.host .. ngx.var.request_uri
358+
ngx.redirect(https_uri, 301)
359+
end
360+
}
361+
```
362+
363+
## Advanced Let's Encrypt Configuration
341364

342365
Internally, lua-resty-auto-ssl uses [dehydrated](https://github.com/lukas2511/dehydrated) as it's Let's Encrypt client. If you'd like to adjust lower-level settings, like the private key size, public key algorithm, or your registration e-mail, these settings can be configured in a custom dehydrated configuration file.
343366

lib/resty/auto-ssl.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ function _M.challenge_server(self)
9999
server(self)
100100
end
101101

102-
function _M.has_certificate(self, domain)
102+
function _M.has_certificate(self, domain, shmem_only)
103103
local has_certificate = require "resty.auto-ssl.utils.has_certificate"
104-
return has_certificate(self, domain)
104+
return has_certificate(self, domain, shmem_only)
105105
end
106106

107107
function _M.hook_server(self)

0 commit comments

Comments
 (0)