Caddy Snippet

Caddy snippet လေးတွေ ဖန်တီးထားပြီး သုံးရတာ တော်တော်အဆင်ပြေတယ်။ ရေးရတာလည်းလွယ်တယ်။ အခုလက်ရှိ လုပ်ထားသည့် snippet တွေကို ဒီမှာ လာမှတ်ထားတာပါ။

Laravel-App

(laravel-app) {
        {args.0} {
                # Resolve the root directory for the app
                root * {args.1}/public

        log {
                output file /var/log/caddy/{args.0}.access.log {
                        roll_size 100mb
                        roll_keep 30
                        roll_keep_for 720h
                }
                format console
                level DEBUG
        }
        # Provide Zstd and Gzip compression
        encode zstd gzip

        # Enable PHP-FPM
        php_fastcgi unix//run/php/php{args.2}-fpm.sock

        # Allow caddy to serve static files
        file_server
    }
}

ပြန်သုံးမယ်ဆိုရင်

import  snippets/*
import laravel-app example.domain.com /var/www/example.domain.com "8.1"

args ဆိုတာက argument တွေ pass လုပ်ပေးဖို့ပါပဲ။ domain , direcotry နဲ့ PHP FPM အတွက် version တွေကို pass လုပ်ထားပေးဖို့ပဲ လိုတယ်။

PHP

(normal-php) {
        {args.0} {
                # Resolve the root directory for the app
                root * {args.1}

        log {
                output file /var/log/caddy/{args.0}.access.log {
                        roll_size 100mb
                        roll_keep 30
                        roll_keep_for 720h
                }
                format console
                level DEBUG
        }
        # Provide Zstd and Gzip compression
        encode zstd gzip

        # Enable PHP-FPM
        php_fastcgi unix//run/php/php{args.2}-fpm.sock

        # Allow caddy to serve static files
        file_server
    }
}

ပုံမှန် PHP ဆိုရင် public folder အောက်က မဟုတ်တော့ပဲ တိုက်ရိုက် ခေါ်ထားပါတယ်။

NodeJS

(nodejs-app) {
        {args.0} {
                # Resolve the root directory for the app
                reverse_proxy localhost:{args.1}
                log {
                output file /var/log/caddy/{args.0}.access.log {
                        roll_size 100mb
                        roll_keep 30
                        roll_keep_for 720h
                }
                format console
                level DEBUG
        }
        # Provide Zstd and Gzip compression
        encode zstd gzip

        file_server
    }
}

localhost ကို port နဲ့ ပြန်ခေါ်ထားတာ ဖြစ်လို့ domain နဲ့ port ပဲ pass လုပ်ပေးဖို့လိုပါတယ်။

import nodejs-app sub.domain.com 3001

အခုတလော Caddy ကို တော်တော်သဘောကျတယ်။ configuration လွယ်သလို https လည်းပါတယ်။ performance လည်း ကောင်းသည့် web server တစ်ခုပါ။