mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-12 14:16:55 -05:00
services: nginx: Add lua module.
* 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.
This commit is contained in:
parent
e835c03e44
commit
00014f7692
3 changed files with 101 additions and 6 deletions
|
@ -1353,6 +1353,7 @@ reference.
|
||||||
* Running Guix on a Linode Server:: Running Guix on a Linode Server
|
* 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.
|
* 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.
|
* 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
|
@end menu
|
||||||
|
|
||||||
@node Customizing the Kernel
|
@node Customizing the Kernel
|
||||||
|
@ -2114,6 +2115,63 @@ sudo herd set-http-proxy guix-daemon http://localhost:9250
|
||||||
guix build --substitute-urls=https://bp7o7ckwlewr4slm.onion …
|
guix build --substitute-urls=https://bp7o7ckwlewr4slm.onion …
|
||||||
@end example
|
@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 *********************************************************************
|
@c *********************************************************************
|
||||||
@node Advanced package management
|
@node Advanced package management
|
||||||
@chapter Advanced package management
|
@chapter Advanced package management
|
||||||
|
|
|
@ -21984,7 +21984,29 @@ names of loadable modules, as in this example:
|
||||||
(modules
|
(modules
|
||||||
(list
|
(list
|
||||||
(file-append nginx-accept-language-module "\
|
(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
|
@end lisp
|
||||||
|
|
||||||
@item @code{global-directives} (default: @code{'((events . ()))})
|
@item @code{global-directives} (default: @code{'((events . ()))})
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
|
;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
|
||||||
;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
|
;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
|
||||||
;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
|
;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
|
||||||
|
;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -525,6 +526,10 @@ (define-record-type* <nginx-configuration>
|
||||||
(modules nginx-configuration-modules (default '()))
|
(modules nginx-configuration-modules (default '()))
|
||||||
(global-directives nginx-configuration-global-directives
|
(global-directives nginx-configuration-global-directives
|
||||||
(default '((events . ()))))
|
(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
|
(extra-content nginx-configuration-extra-content
|
||||||
(default ""))
|
(default ""))
|
||||||
(file nginx-configuration-file ;#f | string | file-like
|
(file nginx-configuration-file ;#f | string | file-like
|
||||||
|
@ -630,6 +635,8 @@ (define (default-nginx-config config)
|
||||||
server-names-hash-bucket-max-size
|
server-names-hash-bucket-max-size
|
||||||
modules
|
modules
|
||||||
global-directives
|
global-directives
|
||||||
|
lua-package-path
|
||||||
|
lua-package-cpath
|
||||||
extra-content)
|
extra-content)
|
||||||
(apply mixed-text-file "nginx.conf"
|
(apply mixed-text-file "nginx.conf"
|
||||||
(flatten
|
(flatten
|
||||||
|
@ -646,11 +653,19 @@ (define (default-nginx-config config)
|
||||||
" scgi_temp_path " run-directory "/scgi_temp;\n"
|
" scgi_temp_path " run-directory "/scgi_temp;\n"
|
||||||
" access_log " log-directory "/access.log;\n"
|
" access_log " log-directory "/access.log;\n"
|
||||||
" include " nginx "/share/nginx/conf/mime.types;\n"
|
" include " nginx "/share/nginx/conf/mime.types;\n"
|
||||||
(if server-names-hash-bucket-size
|
(if lua-package-path
|
||||||
(string-append
|
#~(format #f " lua_package_path ~s;~%"
|
||||||
" server_names_hash_bucket_size "
|
(string-join (map (lambda (path)
|
||||||
(number->string server-names-hash-bucket-size)
|
(string-append path "/lib/?.lua"))
|
||||||
";\n")
|
'#$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
|
(if server-names-hash-bucket-max-size
|
||||||
(string-append
|
(string-append
|
||||||
|
|
Loading…
Reference in a new issue