Skip to content

Instantly share code, notes, and snippets.

@pintsized
Last active January 17, 2018 16:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pintsized/f56c4232a62fd56a4e8fcdc68ebf70de to your computer and use it in GitHub Desktop.
Save pintsized/f56c4232a62fd56a4e8fcdc68ebf70de to your computer and use it in GitHub Desktop.
ledge config
init_by_lua_block {
-- This configures ledge, and can only be done during init. If you skip this, default Redis connection
-- details will be assumed.
--
-- The only things configured here are the main metadata Redis connection, and the Qless Redis DB.
-- Any unknown config will error hard on server load
require("ledge").configure({
redis_connector_params = { -- anything supported by lua-resty-redis-connector works here
url = "redis://127.0.0.1:6380/1",
},
qless_db = 3,
})
-- The sets defaults for all handlers created from the ledge create_handler factory
-- See below for handler config defaults
-- Any unknown config will error hard on server load
require("ledge").set_handler_defaults({
upstream_host = "135.12.512.1",
upstream_port = 81,
storage_driver_config = {
-- Storage Redis could be the same Redis as the metadata one, or separate,
-- or a cluster behind a proxy, or roll your own storage backend with a compatible API
redis_connector_params = { -- anything supported by lua-resty-redis-connector works here
url = "redis://127.0.0.1:6381/0,
},
}
})
}
-- create_worker can take a config table, see defaults in lib/ledge/worker.lua
init_worker_by_lua_block {
require("ledge").create_worker():run()
}
-- now in your location blocks, create a handler and run it
location / {
content_by_lua_block {
require("ledge").create_handler():run()
}
}
-- or pass in some config overring defaults
location / {
content_by_lua_block {
require("ledge").create_handler({
upstream_port = 81,
esi_enabled = true,
}):run()
}
}
-- or bind to one or more events
location / {
content_by_lua_block {
local handler = require("ledge").create_handler()
handler:bind("before_save", function(res)
-- do stuff
end)
handler:run()
}
}
--[[
-- Valid events are
after_cache_read
before_upstream_connect
before_upstream_request
after_upstream_request
before_save
before_save_revalidation_data
before_serve
before_esi_include_request
]]--
-- These are the current handler config defaults, for reference
handler_config = {
storage_driver = "ledge.storage.redis",
storage_driver_config = {},
origin_mode = _M.ORIGIN_MODE_NORMAL, -- TODO rename upstream mode?
-- Note that upstream timeout and keepalive config is shared with outbound
-- ESI request, which are not necessarily configured to use this "upstream"
upstream_connect_timeout = 1000, -- (ms)
upstream_send_timeout = 2000, -- (ms)
upstream_read_timeout = 10000, -- (ms)
upstream_keepalive_timeout = 75000, -- (ms)
upstream_keepalive_poolsize = 64,
upstream_host = "",
upstream_port = 80,
upstream_use_ssl = false,
upstream_ssl_server_name = "",
upstream_ssl_verify = true,
buffer_size = 2^16,
advertise_ledge = true,
keep_cache_for = 86400 * 30, -- (sec)
minimum_old_entity_download_rate = 56,
esi_enabled = false,
esi_content_types = { "text/html" },
esi_allow_surrogate_delegation = false,
esi_recursion_limit = 10,
esi_args_prefix = "esi_",
esi_custom_variables = {},
esi_max_size = 1024 * 1024, -- (bytes)
enable_collapsed_forwarding = false,
collapsed_forwarding_window = 60 * 1000,
gunzip_enabled = true,
keyspace_scan_count = 10,
cache_key_spec = {
"scheme",
"host",
"port",
"uri",
"args",
},
max_uri_args = 100,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment