]> Sergey Matveev's repositories - godlighty.git/commitdiff
Small comments
authorSergey Matveev <stargrave@stargrave.org>
Sun, 31 Oct 2021 08:30:17 +0000 (11:30 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 31 Oct 2021 08:58:48 +0000 (11:58 +0300)
12 files changed:
doc/cfg.texi [new file with mode: 0644]
doc/index.texi
doc/usage.texi [new file with mode: 0644]
rc/example.cfg/blog.stargrave.org.go
rc/example.cfg/git.go
rc/example.cfg/go.go
rc/example.cfg/if.mirror.cypherpunks.ru.go
rc/example.cfg/lists.cypherpunks.ru.go
rc/example.cfg/proxied-host.go
rc/example.cfg/static.go
rc/fcgi.example.cfg/fcgi.go [moved from rc/fcgi/fcgi.go with 100% similarity]
rc/fcgi.example.cfg/init.go [new file with mode: 0644]

diff --git a/doc/cfg.texi b/doc/cfg.texi
new file mode 100644 (file)
index 0000000..79b3d05
--- /dev/null
@@ -0,0 +1,136 @@
+@node Configuration
+@unnumbered Configuration
+
+Initially @command{godlighty} has basic static files handlers (with
+compression, HTTP preconditions are enabled of course). In the example
+below there are nearly all default functions.
+Also look for @file{rc/example.cfg}.
+
+@verbatim
+Hosts["example.com"] = &godlighty.HostCfg{
+    Root: "/www/example.com",
+    TLS: &godlighty.TLSCfg{
+        Cert: "/path/to/example.com.pem",
+        Key: "/path/to/example.com.key.pem",
+        CACert: "/path/to/ca.pem",
+    },
+    DirList: true,
+    WebDAV: true,
+    MIMEs: map[string]string{
+        ".special": "text/x-special-type",
+    },
+}
+@end verbatim
+
+If your keys and certificates are in single file and you use common CA
+certificate, then it is trivial to DRY:
+
+@verbatim
+var (
+    Etc = "/whatever"
+    CACert = path.Join(Etc, "ca.pem")
+)
+
+func newTLSCfg(host string) *godlighty.TLSCfg {
+    return &godlighty.TLSCfg{
+        Cert:   path.Join(Etc, host+".pem"),
+        Key:    path.Join(Etc, host+".pem"),
+        CACert: CACert,
+    }
+}
+@end verbatim
+
+But there are hooks that can do anything more. For example if you want
+to run CGI script or make a redirection (FastCGI handler example is in
+@file{rc/fcgi.example.cfg}):
+
+@verbatim
+HostCfg{
+    ...,
+    Hooks: []godlighty.Hook{
+        func(w http.ResponseWriter, r *http.Request) bool {
+            if r.URL.Path == "/" {
+                http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently)
+                return true
+            }
+            return false
+        },
+        func(w http.ResponseWriter, r *http.Request) bool {
+            cgi.Handler{
+                Path: "/usr/local/libexec/git-core/git-http-backend",
+                Dir:  "/var/empty",
+                Env: []string{
+                    "GIT_PROJECT_ROOT=" + root,
+                    "GIT_HTTP_EXPORT_ALL=",
+                },
+            }.ServeHTTP(w, r)
+            return true
+        },
+    },
+@end verbatim
+
+You can separate your configuration files and add them through
+@code{init()} call:
+
+@verbatim
+$ ls rc/stargrave.org.cfg
+blog.stargrave.org.go
+ca.cypherpunks.ru.go
+cgi.go
+cryptoanarchy.ru.go
+git.go
+go.go
+if.mirror.cypherpunks.ru.go
+lists.cypherpunks.ru.go
+static.go
+tls.go
+[...]
+
+$ cat rc/stargrave.org.cfg/static.go
+package rc
+
+import "path"
+
+func addStaticCfg(host, root string) {
+    if !path.IsAbs(root) {
+        root = path.Join(WWW, root)
+    }
+    godlighty.Hosts[host] = &godlighty.HostCfg{
+        Root: root,
+        TLS:  newTLSCfg(host),
+    }
+}
+
+func addStaticListedDir(host, root string) {
+    addStaticCfg(host, root)
+    godlighty.Hosts[host].DirList = true
+    godlighty.Hosts[host].WebDAV = true
+}
+
+func init() {
+    [...]
+    addStaticCfg("paster.stargrave.org", "/storage/paster/pastes")
+    addStaticCfg("www.godlighty.stargrave.org", "godlighty.stargrave.org")
+    addStaticCfg("www.nncpgo.org", "nncpgo.org")
+    addStaticListedDir("www.mds.cypherpunks.ru", "/storage/audiobook/mds")
+    [...]
+}
+@end verbatim
+
+There are some preexisting helpers to deal with:
+
+@table @file
+
+@item rc/cgi.go
+CGI scripts.
+
+@item rc/redirect.go
+Loggable redirects.
+
+@item rc/mime.go, rc/mime/*
+Predefined @code{Content-Type} entries. Each file in @file{rc/mime/*}
+has tab-separated format: file's extension, media type and optional
+@code{c} mark, meaning that these type can be transparently compressed
+on-the-fly.
+
+@end table
index 4be54c80cd9b52126b205102ed5e9651aaa026d2..cfb612ff2710fc187804ae1bafb2a11539280e24 100644 (file)
@@ -9,8 +9,9 @@ Copyright @copyright{} 2021 @email{stargrave@@stargrave.org, Sergey Matveev}
 @node Top
 @top godlighty
 
-@command{godlighty} is highly-customizable HTTP, HTTP/2, HTTPS server
-written on pure Go.
+@command{godlighty} is
+@url{https://www.gnu.org/philosophy/free-sw.html, free software}
+highly-customizable HTTP, HTTP/2, HTTPS server written on pure Go.
 
 Why yet another web-server? Because all others suck even for my simple
 ordinary needs: they use hateful OpenSSL, lacks documentation, has
@@ -61,126 +62,10 @@ have to recompile it every time configuration changes. Is it a problem?
 I doubt, because Go is very fast. But it produces huge statically linked
 executables, you say! Use @command{bsdiff}/@command{bspatch}!
 
-Send @code{SIGINFO} (@code{SIGUSR1} on Linux) signal to get current
-daemon's configuration.
-
-Initially @command{godlighty} has basic static files handlers (with
-compression, HTTP preconditions are enabled of course). In the example
-below there are nearly all default functions.
-
-@verbatim
-Hosts["example.com"] = &godlighty.HostCfg{
-    Root: "/www/example.com",
-    TLS: &godlighty.TLSCfg{
-        Cert: "/path/to/example.com.pem",
-        Key: "/path/to/example.com.key.pem",
-        CACert: "/path/to/ca.pem",
-    },
-    DirList: true,
-    WebDAV: true,
-    MIMEs: map[string]string{
-        ".special": "text/x-special-type",
-    },
-}
-@end verbatim
-
-If your keys and certificates are in single file and you use common CA
-certificate, then it is trivial to DRY:
-
-@verbatim
-var (
-    Etc = "/whatever"
-    CACert = path.Join(Etc, "ca.pem")
-)
-
-func newTLSCfg(host string) *godlighty.TLSCfg {
-    return &godlighty.TLSCfg{
-        Cert:   path.Join(Etc, host+".pem"),
-        Key:    path.Join(Etc, host+".pem"),
-        CACert: CACert,
-    }
-}
-@end verbatim
-
-But there are hooks that can do anything more. For example if you want
-to run CGI script or make a redirection (FastCGI handler example is in
-@file{rc/fcgi}):
-
-@verbatim
-HostCfg{
-    ...,
-    Hooks: []godlighty.Hook{
-        func(w http.ResponseWriter, r *http.Request) bool {
-            if r.URL.Path == "/" {
-                http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently)
-                return true
-            }
-            return false
-        },
-        func(w http.ResponseWriter, r *http.Request) bool {
-            cgi.Handler{
-                Path: "/usr/local/libexec/git-core/git-http-backend",
-                Dir:  "/var/empty",
-                Env: []string{
-                    "GIT_PROJECT_ROOT=" + root,
-                    "GIT_HTTP_EXPORT_ALL=",
-                },
-            }.ServeHTTP(w, r)
-            return true
-        },
-    },
-@end verbatim
-
-You can separate your configuration files and add them through
-@code{init()} call:
-
-@verbatim
-$ ls rc
-blog.stargrave.org.go
-ca.cypherpunks.ru.go
-cgi.go
-cryptoanarchy.ru.go
-git.go
-go.go
-if.mirror.cypherpunks.ru.go
-lists.cypherpunks.ru.go
-mime.go
-static.go
-tls.go
-[...]
-
-$ cat rc/static
-package rc
-
-import "path"
-
-func addStaticCfg(host, root string) {
-    if !path.IsAbs(root) {
-        root = path.Join(WWW, root)
-    }
-    godlighty.Hosts[host] = &godlighty.HostCfg{
-        Root: root,
-        TLS:  newTLSCfg(host),
-    }
-}
-
-func addStaticListedDir(host, root string) {
-    addStaticCfg(host, root)
-    godlighty.Hosts[host].DirList = true
-    godlighty.Hosts[host].WebDAV = true
-}
-
-func init() {
-    [...]
-    addStaticCfg("paster.stargrave.org", "/storage/paster/pastes")
-    addStaticCfg("www.godlighty.stargrave.org", "godlighty.stargrave.org")
-    addStaticCfg("www.nncpgo.org", "nncpgo.org")
-    addStaticListedDir("www.mds.cypherpunks.ru", "/storage/audiobook/mds")
-    [...]
-}
-@end verbatim
-
 It is created exclusively to drive my own websites, but if you are
 interested, then @code{git clone git://git.stargrave.org/godlighty.git} it.
 
+@include cfg.texi
+@include usage.texi
+
 @bye
diff --git a/doc/usage.texi b/doc/usage.texi
new file mode 100644 (file)
index 0000000..3eb93bd
--- /dev/null
@@ -0,0 +1,39 @@
+@node Usage
+@unnumbered Usage
+
+All @ref{Configuration, configuration} is assumed to be placed in
+@file{rc/cfg}. Probably you want to deal with multiple server
+configurations simultaneously. You place them in corresponding
+@file{rc/NAME.cfg} directories and use @url{http://cr.yp.to/redo.html,
+redo} default target to create necessary symbolic link of
+@file{rc/NAME.cfg} to @file{rc/cfg} and build executable itself.
+
+@example
+$ redo example
+# will produce example executable with rc/example.cfg configuration
+
+$ redo fcgi.example
+# will produce fcgi.example executable with rc/fcgi.example.cfg configuration
+@end example
+
+But because you will mostly like to create binary patches to quickly
+update already existing binaries, then you can use @file{make-update.sh}
+script, that will store newly created binaries in @file{updates/}
+directory and make shell-script with the built-in binary patch and
+SHA512 checksum checker:
+
+@example
+# First run
+$ ./make-update example
+$ scp updates/example.old web-server:/path/to/www-server
+
+$ ./make-update example
+$ scp updates/example-update.sh web-server:/tmp
+web-server $ /tmp/example-update.sh /path/to/www-server
+web-server $ svc -t /var/service/www-server
+@end example
+
+@file{contrib/service} contains @command{daemontools} example run scripts.
+
+Send @code{SIGINFO} (@code{SIGUSR1} on Linux) signal to get current
+daemon's configuration.
index 22ce4a4a52ec57ea3556b1818dc2b17fa7d8ef59..6af0a6950c930dec3145c348c00092f01240fb81 100644 (file)
@@ -1,3 +1,5 @@
+// CGI example
+
 package cfg
 
 import (
index 1e955ed7323e465c38f07901e0df314339a9e599..5803850bafee0f2acf4b031679b1b2b033059aab 100644 (file)
@@ -1,3 +1,5 @@
+// WWW and git:// CGIs
+
 package cfg
 
 import (
index 6d905d3c03789e19fca8317d0b9f56cb8142284f..11efeea060fbbca949778225df112eff2109f13f 100644 (file)
@@ -8,9 +8,10 @@ import (
 
 func addGoRepoCfg(host string) {
        godlighty.Hosts[host] = &godlighty.HostCfg{
-               Root:  path.Join(WWW, host),
-               TLS:   newTLSCfg(host),
-               MIMEs: map[string]string{"": "text/html"},
+               Root:    path.Join(WWW, host),
+               TLS:     newTLSCfg(host),
+               MIMEs:   map[string]string{"": "text/html"},
+               Indexes: []string{"v1"},
        }
 }
 
index 1e1a1dab04179b7497edea54e57ca237e109af04..6743000bc6d34528a1156e5d02c03a8038464ed7 100644 (file)
@@ -1,3 +1,5 @@
+// Some MIMEs overrides example
+
 package cfg
 
 import "go.stargrave.org/godlighty"
index 20b2e63192f616c26723b279738743855378b38a..66322c0fbe4e8b4b6064c3bf8cfc7d148f6b511f 100644 (file)
@@ -1,3 +1,4 @@
+// mlmmj archive browser
 package cfg
 
 import (
index a11f728b61cea2e4c5ca33deea457e3acf0cfabf..0af56cc8b146d9b0596aba19df1c0125b5e32721 100644 (file)
@@ -1,3 +1,5 @@
+// Reverse proxy
+
 package cfg
 
 import (
index 3cbe3fb8a84392b1e0e5cca3233756a0d035aeca..fc56013fb9497e6aa6f3c2d8da33b7b68f9cd889 100644 (file)
@@ -1,3 +1,5 @@
+// Various static directories
+
 package cfg
 
 import (
similarity index 100%
rename from rc/fcgi/fcgi.go
rename to rc/fcgi.example.cfg/fcgi.go
diff --git a/rc/fcgi.example.cfg/init.go b/rc/fcgi.example.cfg/init.go
new file mode 100644 (file)
index 0000000..20e805c
--- /dev/null
@@ -0,0 +1,41 @@
+package cfg
+
+import (
+       "net/http"
+       "strings"
+       "time"
+
+       "go.stargrave.org/godlighty"
+       _ "go.stargrave.org/godlighty/rc"
+)
+
+func init() {
+       docRoot := "/usr/local/www/wordpress"
+       host := "some.wordpress.com"
+       godlighty.Hosts[host] = &godlighty.HostCfg{
+               Root: docRoot,
+               Hooks: []godlighty.Hook{
+                       func(w http.ResponseWriter, r *http.Request) bool {
+                               if r.URL.Path == "/.htaccess" || r.URL.Path == "/xmlrpc.php" {
+                                       http.NotFound(w, r)
+                                       return true
+                               }
+                               return false
+                       },
+                       func(w http.ResponseWriter, r *http.Request) bool {
+                               if strings.TrimSuffix(r.URL.Path, "/") == "" {
+                                       r.URL.Path = "index.php"
+                               }
+                               if strings.HasSuffix(r.URL.Path, ".php") {
+                                       ServeFCGI(
+                                               w, r, host, docRoot, r.URL.Path,
+                                               "unix", "/var/run/php-fpm.sock",
+                                               time.Minute,
+                                       )
+                                       return true
+                               }
+                               return false
+                       },
+               },
+       }
+}