services: web: Add try-files for the nginx-service-type.

* gnu/services/web.scm (<nginx-server-configuration>): Add
  nginx-server-configuration-try-files.
(emit-nginx-server-config): Use it.
* doc/guix.texi (Web Services): Document it.
This commit is contained in:
Oleg Pykhalov 2017-09-23 03:27:49 +03:00 committed by Julien Lepiller
parent 80c3f4d6c0
commit 4d14808af4
No known key found for this signature in database
GPG key ID: 43111F4520086A0C
2 changed files with 12 additions and 1 deletions

View file

@ -14263,7 +14263,8 @@ blocks, as in this example:
(https-port #f)
(ssl-certificate #f)
(ssl-certificate-key #f)
(root "/srv/http/extra-website"))))
(root "/srv/http/extra-website")
(try-files (list "$uri" "$uri/index.html")))))
@end example
@end deffn
@ -14394,6 +14395,10 @@ server block.
Index files to look for when clients ask for a directory. If it cannot be found,
Nginx will send the list of files in the directory.
@item @code{try-files} (default: @code{'()})
A list of files whose existence is checked in the specified order.
@code{nginx} will use the first file it finds to process the request.
@item @code{ssl-certificate} (default: @code{"/etc/nginx/cert.pem"})
Where to find the certificate for secure connections. Set it to @code{#f} if
you don't have a certificate or you don't want to use HTTPS.

View file

@ -99,6 +99,8 @@ (define-record-type* <nginx-server-configuration>
(default '()))
(index nginx-server-configuration-index
(default (list "index.html")))
(try-files nginx-server-configuration-try-files
(default '()))
(ssl-certificate nginx-server-configuration-ssl-certificate
(default "/etc/nginx/cert.pem"))
(ssl-certificate-key nginx-server-configuration-ssl-certificate-key
@ -179,6 +181,7 @@ (define (emit-nginx-server-config server)
(nginx-server-configuration-ssl-certificate-key server))
(root (nginx-server-configuration-root server))
(index (nginx-server-configuration-index server))
(try-files (nginx-server-configuration-try-files server))
(server-tokens? (nginx-server-configuration-server-tokens? server))
(locations (nginx-server-configuration-locations server)))
(define-syntax-parameter <> (syntax-rules ()))
@ -207,6 +210,9 @@ (define-syntax-rule (and/l x tail ...)
(and/l ssl-certificate-key " ssl_certificate_key " <> ";\n")
" root " root ";\n"
" index " (config-index-strings index) ";\n"
(if (not (nil? try-files))
(and/l (config-index-strings try-files) " try_files " <> ";\n")
"")
" server_tokens " (if server-tokens? "on" "off") ";\n"
"\n"
(map emit-nginx-location-config locations)