file-server command: Use safer defaults; http: improve host matcher docs

This commit is contained in:
Matthew Holt 2019-12-31 16:57:54 -07:00
parent 5a0603ed72
commit 788462bd4c
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
2 changed files with 16 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import (
"flag" "flag"
"log" "log"
"strconv" "strconv"
"time"
"github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig" "github.com/caddyserver/caddy/v2/caddyconfig"
@ -32,7 +33,7 @@ func init() {
caddycmd.RegisterCommand(caddycmd.Command{ caddycmd.RegisterCommand(caddycmd.Command{
Name: "file-server", Name: "file-server",
Func: cmdFileServer, Func: cmdFileServer,
Usage: "[--domain <example.com>] [--path <path>] [--listen <addr>] [--browse]", Usage: "[--domain <example.com>] [--root <path>] [--listen <addr>] [--browse]",
Short: "Spins up a production-ready file server", Short: "Spins up a production-ready file server",
Long: ` Long: `
A simple but production-ready file server. Useful for quick deployments, A simple but production-ready file server. Useful for quick deployments,
@ -83,7 +84,10 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
} }
server := &caddyhttp.Server{ server := &caddyhttp.Server{
Routes: caddyhttp.RouteList{route}, ReadHeaderTimeout: caddy.Duration(10 * time.Second),
IdleTimeout: caddy.Duration(30 * time.Second),
MaxHeaderBytes: 1024 * 10,
Routes: caddyhttp.RouteList{route},
} }
if listen == "" { if listen == "" {
if certmagic.HostQualifies(domain) { if certmagic.HostQualifies(domain) {

View File

@ -34,6 +34,16 @@ import (
type ( type (
// MatchHost matches requests by the Host value (case-insensitive). // MatchHost matches requests by the Host value (case-insensitive).
//
// When used in an HTTP route,
// [qualifying domain names](/docs/automatic-https#hostname-requirements)
// may trigger [automatic HTTPS](/docs/automatic-https), which automatically
// provisions and renews certificates for you. Before doing this, you
// should ensure that DNS records for these domains are properly configured,
// especially A/AAAA pointed at your server.
//
// Automatic HTTPS can be
// [customized or disabled](/docs/json/apps/http/servers/automatic_https/).
MatchHost []string MatchHost []string
// MatchPath matches requests by the URI's path (case-insensitive). // MatchPath matches requests by the URI's path (case-insensitive).