How to set up Caddy to work with a web app build with django "run" with docker-compose

1. Caddy version (caddy version):

caddy version
v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

I don’t know. This my first time trying to use Caddy.
This is what I have tried:
modified the “/etc/caddy/Caddyfile” as below

# this machine's public IP, then replace the line below with your
# domain name.
ijs.moe

# Set this path to your site's directory.
root * /app/ijs

# Enable the static file server.
file_server

www.ijs.moe {
    reverse_proxy 127.0.0.1:8001
}

api.ijs.moe {
    reverse_proxy 127.0.0.1:8002
}

a. System environment:

cat /etc/redhat-release
CentOS Linux release 8.3.2011

docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.41
Go version: go1.13.15

docker-compose version
docker-compose version 1.28.6, build 5db8d86f
docker-py version: 4.4.4
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8679a3692684 ijs:latest “/app/entrypoints/ap…” 11 minutes ago Up 11 minutes (healthy) 8001/tcp, 0.0.0.0:8002->8002/tcp ijs_api
aea9a426f613 ijs:latest “/app/entrypoints/cr…” 11 minutes ago Up 11 minutes 8001-8002/tcp ijs_cron
420d1a35e347 ijs:latest “/app/entrypoints/de…” 11 minutes ago Up 11 minutes (healthy) 0.0.0.0:8001->8001/tcp, 8002/tcp ijs_admin
9e8ae0ba604a postgres:12.5 “docker-entrypoint.s…” 11 minutes ago Up 11 minutes 5432/tcp ijs_db

b. Command:

paste command here

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
ijs.moe

# Set this path to your site's directory.
root * /app/ijs

# Enable the static file server.
file_server

www.ijs.moe {
	reverse_proxy 127.0.0.1:8001
}

api.ijs.moe {
	reverse_proxy 127.0.0.1:8002
}

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

3. The problem I’m having:

I am trying to use Caddy, when when I / others visit my site. it will serve as ijs.moe without needing the port 8001. and would like to have https for my site.

4. Error messages and/or full log output:

[root@ijs ]# sudo systemctl status caddy
● caddy.service - Caddy
Loaded: loaded (/usr/lib/systemd/system/caddy.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2021-04-03 17:07:05 UTC; 14s ago
Docs: Welcome — Caddy Documentation
Process: 140107 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAILURE)
Main PID: 140107 (code=exited, status=1/FAILURE)

Apr 03 17:07:05 ijs caddy[140107]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Apr 03 17:07:05 ijs caddy[140107]: HOME=/var/lib/caddy
Apr 03 17:07:05 ijs caddy[140107]: LOGNAME=caddy
Apr 03 17:07:05 ijs caddy[140107]: USER=caddy
Apr 03 17:07:05 ijs caddy[140107]: INVOCATION_ID=712b443ee5ab413e8b0a303c13a6be6c
Apr 03 17:07:05 ijs caddy[140107]: JOURNAL_STREAM=9:173097
Apr 03 17:07:05 ijs caddy[140107]: {“level”:“info”,“ts”:1617469625.2124047,“msg”:“using provided configuration”,“config_file”:"/etc/caddy/Caddyfile",“config_adapter”:""}
Apr 03 17:07:05 ijs caddy[140107]: run: adapting config using caddyfile: /etc/caddy/Caddyfile:18: unrecognized directive: www.ijs.moe
Apr 03 17:07:05 ijs systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Apr 03 17:07:05 ijs systemd[1]: caddy.service: Failed with result ‘exit-code’.
[root@ijs ]# vim /etc/caddy/Caddyfile

5. What I already tried:

I followed the guide given by the default Caddy

Your web server is working. Now make it work for you. :muscle:

Caddy is ready to serve your site over HTTPS:

Point your domain's A/AAAA DNS records at this machine.
Upload your site's files to /var/www/html.
Edit your Caddyfile at /etc/caddy/Caddyfile:
    Replace :80 with your domain name
    Change the site root to /var/www/html
Reload the configuration: systemctl reload caddy
Visit your site!

6. Links to relevant resources:

www.ijs.moe:8001
www.ijs.moe:80

Please read through the Caddyfile structure docs:

If you have more than one site to serve, you must use braces around each site. Explained in the “Blocks” section.

This topic was automatically closed after 30 days. New replies are no longer allowed.