30 lines
1.3 KiB
Markdown
30 lines
1.3 KiB
Markdown
# Caddy web server and reverse proxy
|
|
|
|
Usually we will have multiple services and websites running on our VPS. So we need a web server which will listen on `HTTP` and `HTTPS` ports and redirect the traffic to correct service.
|
|
|
|
## Installation
|
|
|
|
I'll install caddy as a `systemd` service on my ubuntu machine. Hence I'll following [debian docs](https://caddyserver.com/docs/install#debian-ubuntu-raspbian) to install caddy.
|
|
To verify if caddy is installed and running run the following command.
|
|
```bash
|
|
sudo service caddy status
|
|
```
|
|
Caddy web server is now started on your VPS and you can visit `domain-name.com` and see the caddy homepage. Caddy homepage will tell you where to edit caddy config and where you can put your static files for your webserver.
|
|
|
|
## TLS Certificates
|
|
|
|
Right now Caddy is running on HTTP only `80` port. To use automatic HTTPS replace the `:80` port in caddy config to your domain name.
|
|
Before that ensure DNS record of domain name points to IP address of VPS.
|
|
```diff
|
|
- :80 {
|
|
+ domain-name.com {
|
|
}
|
|
```
|
|
|
|
After making any change to caddy config we also need to restart the caddy service.
|
|
```bash
|
|
sudo systemctl reload caddy
|
|
```
|
|
Now visit `domain-name.com` again and it will be serving site over HTTPS.
|
|
Caddy will automatically provision and renew TLS certificates from [LetsEncrypt](https://letsencrypt.org)
|