Difference between revisions of "Caddy config examples"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with "``` { http_port 8080 https_port 8443 } # http://domain.com:8080 { http://testlocal.uvoo.io:8080 { # Change the path here according to your setup...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
# Examples
 +
 +
## install
 +
```
 +
#!/bin/bash
 +
set -eu
 +
# version=2.6.2
 +
version=2.5.2
 +
curl -LO https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_amd64.tar.gz \
 +
  && tar xzf caddy_${version}_linux_amd64.tar.gz \
 +
  && ./caddy version
 +
 +
# https://github.com/caddyserver/caddy/releases/download/v2.6.2/caddy_2.6.2_linux_amd64.deb
 +
```
 +
 +
## Format & load
 +
```
 +
#!/bin/bash
 +
set -eux
 +
 +
caddy fmt --overwrite a.caddy
 +
caddy adapt --config a.caddy > a.json
 +
# ./caddy run --config a.json
 +
curl localhost:2019/load -H "Content-Type: application/json" -d @a.json
 +
```
 +
 +
## Config example
 
```
 
```
 
{
 
{
        http_port 8080
+
    # admin off
        https_port 8443
+
    admin :12019
 +
    http_port 8080
 +
    https_port 8443
 
}
 
}
  
# http://domain.com:8080 {
+
 
 
http://testlocal.uvoo.io:8080 {
 
http://testlocal.uvoo.io:8080 {
        # Change the path here according to your setup
+
    # Change the path here according to your setup
        # root * /var/www/domain.com
+
    # root * /var/www/domain.com
        # root * /home/busk/caddy/domains/localtest.uvoo.io
+
    # root * /home/busk/caddy/domains/localtest.uvoo.io
        root * ./domains/testlocal.uvoo.io
+
    root * ./domains/testlocal.uvoo.io
        encode zstd gzip
+
    encode zstd gzip
        file_server
+
    file_server
  
        @cache {
+
    @cache {
                not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
+
        not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
                not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
+
        not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
                not method POST
+
        not method POST
                not expression {query} != ''
+
        not expression {query} != ''
        }
+
    }
  
        route @cache {
+
    route @cache {
                try_files /wp-content/cache/cache-enabler/{host}{uri}/https-index.html /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
+
        try_files /wp-content/cache/cache-enabler/{host}{uri}/https-index.html /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
        }
+
    }
  
        # Change the path here according to your server
+
    # Change the path here according to your server
        php_fastcgi unix//run/php/php7.4-fpm.sock
+
    php_fastcgi unix//run/php/php7.4-fpm.sock
 
}
 
}
  
 
http://testlocal1.uvoo.io:8080 {
 
http://testlocal1.uvoo.io:8080 {
        root * ./domains/testlocal1.uvoo.io
+
    root * ./domains/testlocal1.uvoo.io
        encode zstd gzip
+
    encode zstd gzip
        file_server
+
    file_server
        log {
+
    log {
                output file ./logs/testlocal1.uvoo.io.8080-access.log
+
        output file ./logs/testlocal1.uvoo.io.8080-access.log
        }
+
    }
 
}
 
}
  
 
https://testlocal2.uvoo.io:8443 {
 
https://testlocal2.uvoo.io:8443 {
        root * ./domains/testlocal2.uvoo.io
+
    root * ./domains/testlocal2.uvoo.io
        encode zstd gzip
+
    encode zstd gzip
        file_server
+
    file_server
        tls ./certs/selfsigned.crt ./certs/selfsigned.key
+
    tls ./certs/selfsigned.crt ./certs/selfsigned.key
        log {
+
    log {
                output file ./logs/testlocal2.uvoo.io.8443-access.log
+
        output file ./logs/testlocal2.uvoo.io.8443-access.log
        }
+
    }
 
}
 
}
 
```
 
```

Latest revision as of 15:38, 23 January 2023

Examples

install

#!/bin/bash
set -eu
# version=2.6.2
version=2.5.2
curl -LO https://github.com/caddyserver/caddy/releases/download/v${version}/caddy_${version}_linux_amd64.tar.gz \
  && tar xzf caddy_${version}_linux_amd64.tar.gz \
  && ./caddy version

# https://github.com/caddyserver/caddy/releases/download/v2.6.2/caddy_2.6.2_linux_amd64.deb

Format & load

#!/bin/bash
set -eux

caddy fmt --overwrite a.caddy
caddy adapt --config a.caddy > a.json
# ./caddy run --config a.json
curl localhost:2019/load -H "Content-Type: application/json" -d @a.json

Config example

{
    # admin off
    admin :12019
    http_port 8080
    https_port 8443
}


http://testlocal.uvoo.io:8080 {
    # Change the path here according to your setup
    # root * /var/www/domain.com
    # root * /home/busk/caddy/domains/localtest.uvoo.io
    root * ./domains/testlocal.uvoo.io
    encode zstd gzip
    file_server

    @cache {
        not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
        not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
        not method POST
        not expression {query} != ''
    }

    route @cache {
        try_files /wp-content/cache/cache-enabler/{host}{uri}/https-index.html /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
    }

    # Change the path here according to your server
    php_fastcgi unix//run/php/php7.4-fpm.sock
}

http://testlocal1.uvoo.io:8080 {
    root * ./domains/testlocal1.uvoo.io
    encode zstd gzip
    file_server
    log {
        output file ./logs/testlocal1.uvoo.io.8080-access.log
    }
}

https://testlocal2.uvoo.io:8443 {
    root * ./domains/testlocal2.uvoo.io
    encode zstd gzip
    file_server
    tls ./certs/selfsigned.crt ./certs/selfsigned.key
    log {
        output file ./logs/testlocal2.uvoo.io.8443-access.log
    }
}