Install and configure Caddy Server

Tram Ho

Preamble

You are familiar with traditional web servers such as Nginx, Apache, … I think you should try caddyserver. You will no longer worry, tired of having to go to read documents, search through the configuration settings for the system to work smoothly. Instead, you only need 1 minute to create and configure the server with just a few lines of code for the server system to start running. It is extremely simple, and the documents are bright and easy to understand, so maybe in the near future it will be a rival of nginx.

Introduce

Caddy is a powerful web server platform, written in Go as an open-source and being developed very strongly by the community. It targets HTTP / 2.0 and uses HTTPS by default. It is also a great option for: load balancing, api port, ingress controller, process supervisor, task scheduler.

Setting

You can download it directly from github using curl:

Use wget:

Install for Debian, Ubuntu, Raspbian

Install for Fedora, RedHat, CentOS

Fedora or RHEL / CentOS 8:

RHEL / CentOS 7:

Install for macOS

After the installation is complete you can check if the caddy is working with the command:

Check the status of caddy:

You can stop the caddy with the command:

To get changes in the config file you can run:

Note: Do not stop the service when changing the config. Stopping the service will result in system downtime. Instead, use the reload command instead.

Configuration

Caddy gives us 2 ways to configure with JSON file and Caddyfile:

With Jsonfile

First we create a json file with the following content:

To apply this file we need to use an api of candy:

To check if we have successfully configured or not, use the command:

if “Hello, world!” appears congratulations you have successfully configured. You can refer to JSON document. here. https://caddyserver.com/docs/json/

with Caddyfile

To configure with caddyfile you need to create a file named Caddyfile To run the “Helllo world” application as above, with Caddyfile is completely simple as follows:

As the configuration file above has localhost this is the domain name you need to configure. In addition, to configure https for Caddy Server you can quickly configure using internal tls config, Caddy will use the local certificate file for this site.

Application

Let’s say our web application has a frontend built with nuxtjs and is running at port 3000. and the backend laravel api runs at port 8000. so how to forward into this application with Caddy. Very simple you create a Caddyfile file with the following command:

We have already configured the application with: Client: localhost Server API: localhost / api /

Above are 2 common ways of configuring caddy. Try comparing through these 2 configurations. You can refer to the home page here https://caddyserver.com/docs/getting-started

Compare JSON and Caddyfile

Compare pros and cons of json and caddyfile:

Conclude

Caddy is still quite new. and being actively developed by the community. Perhaps one day not too far it will become popular. So find it today. Pro. Hello, Sincerely and win!

Refer :

https://caddyserver.com/

https://www.marketenterprise.vn/

Share the news now

Source : Viblo