The emerging Web server caddy

Source: Internet
Author: User
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/2Fully automatic support of the HTTP/2 protocol without any configuration.

    • Auto HTTPSCaddy 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-coreBecause Caddy is written by Golang, it is reasonable to use multicore.

    • IPv6fully supports the IPV6 environment.

    • WebSocketsCaddy has a good support for websockets.

    • MarkdownAutomatically turns MD into HTML, of course, I'm going to introduce you to the more powerful Hugo to do it.

    • LoggingThe Caddy definition of the log format is easy and better meets the needs of your log collection.

    • Easy DeploymentThanks 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

    1. Download Caddy

    2. 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

    1. Find a temporary directory to test and generate a Test home page.echo "hello world">index.html

    2. Performcaddy

    3. 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.
timeoutsThe keyword is I groped out, the official example does not set this domestic upgrade plugin what the fundamental success.
tlsIn 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.