DEV Community

kunzhu0710
kunzhu0710

Posted on

How to deploy Caddy on Tencent Cloud CVM

Cloud Virtual Machine (CVM) provides you with secure and flexible computing capabilities. You can enable CVM in the cloud in just minutes to meet your diverse computing needs. Through CVM, you can easily scale up or down your computing resources as your business needs change. Billed based on your actual resource consumption, CVM reduces your computing costs and simplifies IT-related OPS.

This is an era of Web Server. Apache and nginx compete for excellence. In the pursuit of ultimate performance, there is no highest, only higher. But this is also an era of pursuit of personalization. Some Web Servers do not squeeze the "Performance Improvement" single-plank bridge, but have their own positioning. Caddy is such an open source Web Server.
Matt Holt, the author of Caddy, explained the goal of caddy in the caddy official website and FAQ as follows: Other Web Servers are designed for the Web, and Caddy is designed for humans. In terms of functional positioning, unlike nginx, which often acts as the front-end reverse proxy, caddy is committed to becoming an easy-to-use static file Web Server. It can be seen that Caddy focuses on ease of use and simple configuration. And thanks to the cross-platform features of Go, caddy easily supports three major platforms: Windows, Linux, and Mac. In the Caddy developer documentation, we can see that caddy can also run on Android (linux arm).
Pay attention to caddy because caddy fills the gap of go in general web server (maybe there are others, but I don't know yet), and at the same time, web server in go also "responds" to the recent trend of de-C in Golang (in Go 1.5 C is gone!), even though the caddy author mentions that caddy is not targeted like nginx. But who knows in the future? Once Go performance is high enough, once caddy is stable enough, someone will naturally use it to replace nginx or apache2 in the production environment of some applications. An all-Go system also has advantages in deployment, operation and maintenance.
A notable feature of Caddy is that HTTPS is enabled by default. It was the first web server to provide HTTPS features without additional configuration. The default certificate is valid for 3 months and can be automatically renewed after expiration, which greatly reduces the cost and convenience of enabling HTTPS for small and medium-sized websites. Caddy enables HTTPS by default by checking the domain name (checking the domain name and issuing the certificate via the ACME protocol), and redirecting HTTP requests to HTTPS. It issues certificates on demand during startup and automatically reissues during server use. Let's Encrypt is the default certificate authority, but the user can customize the ACME CA used, which is necessary when testing the configuration. Of course, users can also configure certificates by themselves.
1. Install Caddy
This article provides a one-click installation of the Caddy script, which is simple and fast without the trivial installation method. Applicable operating systems are: CentOS/Debian/Ubuntu. The installation script can be downloaded on GitHub .
undefined
One-click installation of Caddy scriptsAfter downloading, run the script directly to perform one-click installation. wget --no-check-certificate https://github.com/suxin1110/CaddyInstall/caddy_install.sh && chmod +x caddy_install.sh && ./caddy_install.sh
Caddy uses the command: /usr/local/caddy/Caddyfile
Log file: cat /tmp/caddy.log
Instructions for use: service caddy start | stop | restart | status
Or use: /etc/init.d/caddy start | stop | restart | status
2. Configuration instructions
The file that Caddy needs to configure is Caddyfile, and the default path of this file is /usr/local/caddy/Caddyfile
The Caddyfile always puts the website domain name on the first line:
localhost:8080
gzip
log ../access.log
Configure multisite with one Caddyfile, must use curly braces to enclose each site
mysite.com {
root /www/mysite.com
}
sub.mysite.com:443 {
root /www/sub.mysite.com
gzip
log ../access.log
}
Caddy can also implement the reverse proxy function. Compared with the configuration of other Web Servers, the configuration of Caddyfile reverse proxy can be said to be outstanding, and it only needs one command to achieve
mysite.com:8080 {
log ./mysite.log
proxy /a localhost:9091
proxy /bar localhost:9092
}

Caddy supports load balancing configuration and supports three load balancing algorithms: random (random), least_conn (least connection) and round_robin (round-robin scheduling). Load balancing is also implemented through proxy middleware.
localhost:8080 {
log ./mysite.log
proxy / localhost:9091 localhost:9093 {
policy round_robin
}
proxy /b localhost:9092 localhost:9094 {
policy least_conn
}
}

Top comments (0)