2 Nginx module for Augeas
4 Authors: Ian Berry <iberry@barracuda.com>
5 Raphael Pinson <raphael.pinson@camptocamp.com>
9 This module was built to support a limited subset of nginx
10 configuration syntax. It works fine with simple blocks and
14 This file is licenced under the LGPL v2+, like the rest of Augeas.
19 About: Configuration files
20 This lens applies to /etc/nginx/nginx.conf. See <filter>.
23 The <Test_Nginx> file contains various examples and tests.
26 * Convert statement keyworks for a regex
27 * Support more advanced block syntax (location)
35 let word = /[A-Za-z0-9_.:-]+/
38 The keywords reserved for block entries *)
39 let block_re = "http" | "events" | "server" | "mail" | "stream"
41 (* All block keywords, including the ones we treat specially *)
42 let block_re_all = block_re | "if" | "location" | "geo" | "map"
43 | "split_clients" | "upstream"
48 let kw = word - block_re_all
49 in let mask = [ label "mask" . Util.del_str "/" . store Rx.integer ]
50 in let sto = store /[^ \t\n;#]([^";#]|"[^"]*\")*/
53 (Sep.space . sto)? . Sep.semicolon .
54 (Util.eol|Util.comment_eol) ]
57 A simple server entry *)
59 let address = /[A-Za-z0-9_.:\/-]+/
60 in [ Util.indent . label "@server" . Util.del_str "server"
61 . [ Sep.space . label "@address" . store address ]
62 . [ Sep.space . key word . (Sep.equal . store word)? ]*
64 . (Util.eol|Util.comment_eol) ]
66 let arg (name:string) (rx:regexp) =
67 [ label name . Sep.space . store rx ]
69 (* Match any argument (as much as possible) *)
71 let bare_rx = /[^" \t\n{][^ \t\n{]*/ in
72 let dquote_rx = /"([^\"]|\\.)*"/ in
75 let any_arg (name:string) = arg name any_rx
77 (* 'if' conditions are enclosed in matching parens which we can't match
78 precisely with a regular expression. Instead, we gobble up anything that
79 doesn't contain an opening brace. That can of course lead to trouble if
80 a condition actually contains an opening brace *)
81 let block_if = key "if"
82 . arg "#cond" /\(([^ \t\n{]|[ \t\n][^{])*\)/
84 let block_location = key "location"
85 . (arg "#comp" /=|~|~\*|\^~/)?
88 let block_geo = key "geo"
89 . (any_arg "#address")?
92 let block_map = key "map"
96 let block_split_clients = key "split_clients"
100 let block_upstream = key "upstream"
103 let block_head = key block_re
108 | block_split_clients
112 A block containing <simple> entries *)
113 let block (entry : lens) =
114 [ Util.indent . block_head
115 . Build.block_newlines entry Util.comment
118 let rec directive = simple | server | block directive
121 let lns = ( Util.comment | Util.empty | directive )*
123 (* Variable: filter *)
124 let filter = incl "/etc/nginx/nginx.conf"
125 . incl "/etc/nginx/conf.d/*.conf"
126 . incl "/etc/nginx/sites-available/*"
127 . incl "/etc/nginx/sites-enabled/*"
128 . incl "/usr/portage/www-servers/nginx/files/nginx.conf"
129 . incl "/usr/local/etc/nginx/nginx.conf"
130 . incl "/usr/local/etc/nginx/conf.d/*.conf"
131 . incl "/usr/local/etc/nginx/sites-available/*"
132 . incl "/usr/local/etc/nginx/sites-enabled/*"
134 let xfm = transform lns filter