From: Oleg Pykhalov <go.wigust@gmail.com>
To: 43933@debbugs.gnu.org
Cc: Oleg Pykhalov <go.wigust@gmail.com>
Subject: [bug#43933] [PATCH 8/8] services: nginx: Add lua module.
Date: Sun, 11 Oct 2020 21:30:12 +0300 [thread overview]
Message-ID: <20201011183012.15932-8-go.wigust@gmail.com> (raw)
In-Reply-To: <20201011183012.15932-1-go.wigust@gmail.com>
* gnu/services/web.scm (<nginx-configuration>)
[lua-package-path, lua-package-cpath]: New record types.
* gnu/services/web.scm (default-nginx-config): Use them.
* doc/guix.texi (Web Services): Document this.
* doc/guix-cookbook.texi (System Configuration): Document this.
---
doc/guix-cookbook.texi | 58 ++++++++++++++++++++++++++++++++++++++++++
doc/guix.texi | 24 ++++++++++++++++-
gnu/services/web.scm | 25 ++++++++++++++----
3 files changed, 101 insertions(+), 6 deletions(-)
diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi
index a783c0ae4c..6577c340d9 100644
--- a/doc/guix-cookbook.texi
+++ b/doc/guix-cookbook.texi
@@ -1352,6 +1352,7 @@ reference.
* Running Guix on a Linode Server:: Running Guix on a Linode Server
* Setting up a bind mount:: Setting up a bind mount in the file-systems definition.
* Getting substitutes from Tor:: Configuring Guix daemon to get substitutes through Tor.
+* Setting up NGINX with Lua:: Configuring NGINX web-server to load Lua modules.
@end menu
@node Customizing the Kernel
@@ -2113,6 +2114,63 @@ sudo herd set-http-proxy guix-daemon http://localhost:9250
guix build --substitute-urls=https://bp7o7ckwlewr4slm.onion …
@end example
+@node Setting up NGINX with Lua
+@section Setting up NGINX with Lua
+@cindex nginx, lua, openresty, resty
+
+NGINX could be extended with Lua scripts.
+
+Guix provides NGINX service with ability to load Lua module and specific
+Lua packages, and reply to requests by evaluating Lua scripts.
+
+The following example demonstrates system definition with configuration
+to evaluate @file{index.lua} Lua script on HTTP request to
+@uref{http://localhost/hello} endpoint:
+
+@example
+local shell = require "resty.shell"
+
+local stdin = ""
+local timeout = 1000 -- ms
+local max_size = 4096 -- byte
+
+local ok, stdout, stderr, reason, status =
+ shell.run([[/run/current-system/profile/bin/ls /tmp]], stdin, timeout, max_size)
+
+ngx.say(stdout)
+@end example
+
+@lisp
+(use-modules (gnu))
+(use-service-modules #;… web)
+(use-package-modules #;… lua)
+(operating-system
+ ;; …
+ (services
+ ;; …
+ (service nginx-service-type
+ (nginx-configuration
+ (modules
+ (list
+ (file-append nginx-lua-module "/etc/nginx/modules/ngx_http_lua_module.so")))
+ (lua-package-path (list lua-resty-core
+ lua-resty-lrucache
+ lua-resty-signal
+ lua-tablepool
+ lua-resty-shell))
+ (lua-package-cpath (list lua-resty-signal))
+ (server-blocks
+ (list (nginx-server-configuration
+ (server-name '("localhost"))
+ (listen '("80"))
+ (root "/etc")
+ (locations (list
+ (nginx-location-configuration
+ (uri "/hello")
+ (body (list #~(format #f "content_by_lua_file ~s;"
+ #$(local-file "index.lua"))))))))))))))
+@end lisp
+
@c *********************************************************************
@node Advanced package management
@chapter Advanced package management
diff --git a/doc/guix.texi b/doc/guix.texi
index 8514dfe86f..c8e5928590 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21903,7 +21903,29 @@ names of loadable modules, as in this example:
(modules
(list
(file-append nginx-accept-language-module "\
-/etc/nginx/modules/ngx_http_accept_language_module.so")))
+/etc/nginx/modules/ngx_http_accept_language_module.so")
+ (file-append nginx-lua-module "\
+/etc/nginx/modules/ngx_http_lua_module.so")))
+@end lisp
+
+@item @code{lua-package-path} (default: @code{'()})
+List of nginx lua packages to load. This should be a list of package
+names of loadable lua modules, as in this example:
+
+@lisp
+(lua-package-path (list lua-resty-core
+ lua-resty-lrucache
+ lua-resty-signal
+ lua-tablepool
+ lua-resty-shell))
+@end lisp
+
+@item @code{lua-package-cpath} (default: @code{'()})
+List of nginx lua C packages to load. This should be a list of package
+names of loadable lua C modules, as in this example:
+
+@lisp
+(lua-package-cpath (list lua-resty-signal))
@end lisp
@item @code{global-directives} (default: @code{'((events . ()))})
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index c8ffc19d83..d17faa2b59 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -13,6 +13,7 @@
;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -525,6 +526,10 @@
(modules nginx-configuration-modules (default '()))
(global-directives nginx-configuration-global-directives
(default '((events . ()))))
+ (lua-package-path nginx-lua-package-path ;list of <package>
+ (default #f))
+ (lua-package-cpath nginx-lua-package-cpath ;list of <package>
+ (default #f))
(extra-content nginx-configuration-extra-content
(default ""))
(file nginx-configuration-file ;#f | string | file-like
@@ -630,6 +635,8 @@ of index files."
server-names-hash-bucket-max-size
modules
global-directives
+ lua-package-path
+ lua-package-cpath
extra-content)
(apply mixed-text-file "nginx.conf"
(flatten
@@ -646,11 +653,19 @@ of index files."
" scgi_temp_path " run-directory "/scgi_temp;\n"
" access_log " log-directory "/access.log;\n"
" include " nginx "/share/nginx/conf/mime.types;\n"
- (if server-names-hash-bucket-size
- (string-append
- " server_names_hash_bucket_size "
- (number->string server-names-hash-bucket-size)
- ";\n")
+ (if lua-package-path
+ #~(format #f " lua_package_path ~s;~%"
+ (string-join (map (lambda (path)
+ (string-append path "/lib/?.lua"))
+ '#$lua-package-path)
+ ";"))
+ "")
+ (if lua-package-cpath
+ #~(format #f " lua_package_cpath ~s;~%"
+ (string-join (map (lambda (cpath)
+ (string-append cpath "/lib/lua/?.lua"))
+ '#$lua-package-cpath)
+ ";"))
"")
(if server-names-hash-bucket-max-size
(string-append
--
2.28.0
next prev parent reply other threads:[~2020-10-11 18:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-11 18:19 [bug#43933] [PATCH 0/8] services: nginx: Add lua module Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 2/8] gnu: Add lua-resty-lrucache Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 3/8] gnu: Add lua-resty-signal Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 4/8] gnu: Add lua-tablepool Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 5/8] gnu: Add lua-resty-shell Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 6/8] gnu: Add nginx-socket-cloexec Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 7/8] gnu: Add nginx-lua-module Oleg Pykhalov
2020-10-11 18:30 ` Oleg Pykhalov [this message]
2020-10-14 20:43 ` bug#43933: [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201011183012.15932-8-go.wigust@gmail.com \
--to=go.wigust@gmail.com \
--cc=43933@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.