This is a creation in Article, where the information may have evolved or changed.
Caddy is a Web server like Apache, Nginx, or lighttpd.
You have to ask Nginx is very good, why use caddy? I think the biggest feature of Caddy is simple to use.
And then, it has these out-of-the-box features:
HTTP/2
Fully automatic support of the HTTP/2 protocol without any configuration.
Auto HTTPS
Caddy uses let's Encrypt to make your site fully automated into full-station HTTPS without any configuration. Of course, you can use your own certificate is also possible.
Multi-core
Because Caddy is written by Golang, it is reasonable to use multicore.
IPv6
fully supports the IPV6 environment.
WebSockets
Caddy has a good support for websockets.
Markdown
Automatically turns MD into HTML, of course, I'm going to introduce you to the more powerful Hugo to do it.
Logging
The Caddy definition of the log format is easy and better meets the needs of your log collection.
Easy Deployment
Thanks to the Go feature, Caddy is just a small binary file that has no dependencies and is well deployed.
So what is the scenario for trying to use caddy
, I recommend starting with the following scenario:
Webserver as a static page
Forwarding fastcgi requests to the PHP-FPM service, such as replacing Apache or Nginx as a WordPress server
Reverse proxy, managing multiple sites
Micro-Service API Gateway, I will write an article specifically.
Some of the requirements in nginx difficult to develop, for caddy write plugin too convenient.
Entry
Installing Caddy
Download Caddy
Put the caddy in the path of the system so that it can be executed directly. For example, Linux is generally used to put/usr/local/bin
Simple test
Find a temporary directory to test and generate a Test home page.echo "hello world">index.html
Performcaddy
Access in another terminal curl localhost:2015
or in a browser (http://localhost:2015)
Caddyfile
A feature of Caddy is the simple configuration, nginx configuration file group has been more and more dizzy. Let's try it out:
Create such a called file in the current directory Caddyfile
:
localhost:2020gzip
This time, we changed the port and enabled gzip to compress the data automatically. Run caddy
, go to your designated address to see it.
To say, Caddy's unspoken rule is to find the current directory called Caddyfile
file, you can also use parameters to specify the file and path.
A little more professional.
We casually say a bit of advanced features, in fact, Caddy document is very good, look at the document can understand a variety of features.
Automatic HTTPS
If you meet these conditions, the app you started with Caddy will automatically get HTTPS, without you having to buy a certificate, which is Let's Encrypt
the credit.
Host there to fill in a domain name, cannot be localhost or IP
Do not manually specify a port with a colon
Do not manually declare HTTP before the domain name
The TLS is not switched off in the configuration, or it is declared with its own certificate, but not yet.
Caddy has permissions to bind ports 80 and 443
Can understand the front, say the last one. In the Init folder's boot configuration tutorial, it is generally recommended that you start the service with a www-data user,
You're not root, but Linux still lets you bind 80 ports, just do it setcap cap_net_bind_service=+ep caddy
.
Look at the document in detail.
Multi-site
You may think, before using nginx mainly to support multi-site, caddy of course, you can only configure a number of domain names,
Write the configuration of each domain name in the brace configuration block behind it. In the next example, there is.
PHP or Wordpress
It is said that One-fourth of the world's sites are built on WordPress, and PHP is recognized as the world's best language.
Caddy has not fully supported the UNIX socket communications, and quickly first put PHP support.
This is my own blog configuration fragment, my barren non-technical blog is still used by WordPress.
timeouts
The keyword is I groped out, the official example does not set this domestic upgrade plugin what the fundamental success.
tls
In fact, with the default value is yes, but backstage there will be a lot of backward search engine and crawler error, so I lowered a bit.
In addition, I also directed the WWW to the bare domain name, we generally do this, or vice versa.
xiafeng.net { root /data/xiafeng/public timeouts 10m gzip tls { protocols tls1.0 tls1.2 } fastcgi / unix:/var/run/php/php7.0-fpm.sock php rewrite { if {path} not_match ^\/wp-admin to {path} {path}/ /index.php?_url={uri} }}www.xiafeng.net { redir https://xiafeng.net}
Boot up
Since most distributions do not currently have the ability to install caddy directly, booting up may require you to do it yourself.
There is an init folder in the compressed package you downloaded, with MAC,LINUX,FREEBSD boot configuration help,
There are also sample scripts that can be customized to suit your needs.
Notice
As a primer on this, I will write some fun or professional caddy usage in the next blog. Please look forward to it.