Monica CRM (fpm) in docker with Caddy as web server - can't figure Caddyfile

1. Caddy version (caddy version):

Caddy2

2. How I run Caddy:

Official docker container

a. System environment:

ubuntu 20, docker everything

b. Command:

Paste command here.

c. Service/unit/compose file:

version: '3'

networks:
  docker_dbnet_shared:
    name: ${DOCKER_DBNETWORK_NAME}

caddy:
  image: caddy:2
  container_name: caddy
  restart: always
  ports:
    - 80:80  # Needed for the ACME HTTP-01 challenge.
    - 443:443
  volumes:
    - ./Caddyfile:/etc/caddy/Caddyfile:ro
    - ./caddy-config:/config
    - ./caddy-data:/data
    - ${DOCKER_APPDATA_PATH}/caddy/www:/srv
  environment:
    - EMAIL=some@email.com   # The email address to use for ACME registration.
    - LOG_FILE=/data/accesscaddy.log
    
mysql_db: ######### MySQL shared instance (docker only, no host apps access)
   image: mysql:latest
   container_name: MySQL_DB
   restart: always
   networks:
     - docker_dbnet_shared
   environment:
     - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
   ports:
     - 3306:3306
   volumes:
     - ${DOCKER_APPDATA_PATH}/mysql/data:/var/lib/mysql
     - ${DOCKER_APPDATA_PATH}/mysql/config:/etc/mysql/conf.d

 monica_crm: ######### Monica CRM - personal CRM
   image: monica:fpm
   container_name: Monica_CRM
   networks:
     - docker_dbnet_shared
   restart: always
   depends_on:
     - mysql_db
   env_file:
     - .env_monicaCRM
   environment:
     - DB_HOST=MySQL_DB
#      - APP_ENV=production
   volumes:
     - ${DOCKER_APPDATA_PATH}/caddy/www/monicacrm:/var/www/html/storage

d. My complete Caddyfile or JSON config:

#Monica CRM
some.website {
        header {
                X-Robots-Tag "noindex"
        }
        tls {$EMAIL}
        log {
                output file /data/monicacrmaccess.log {
                        roll_size 10MB
                        roll_keep 10
                }
                level ERROR
                format json
            }

        root * /srv/monicacrm
        php_fastcgi 172.19.0.3:9000
        file_server
}

3. The problem I’m having:

Can’t reach MonicaCRM container when using URL - some.website

4. Error messages and/or full log output:

{“level”:“error”,“ts”:1639433825.3632703,“logger”:“http.log.access.log2”,“msg”:“handled request”,“request”:{“remote_addr”:“73.245.241.235:10203”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“mon.nomid.ws”,“uri”:"/",“headers”:{“Dnt”:[“1”],“Upgrade-Insecure-Requests”:[“1”],“Sec-Fetch-Mode”:[“navigate”],“Sec-Fetch-User”:["?1"],“Cache-Control”:[“max-age=0”],“Te”:[“trailers”],“User-Agent”:[“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0”],“Accept-Encoding”:[“gzip, deflate, br”],“Sec-Fetch-Dest”:[“document”],“Sec-Fetch-Site”:[“none”],“Accept”:[“text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8”],“Accept-Language”:[“en-US,ru;q=0.5”]},“tls”:{“resumed”:false,“version”:772,“cipher_suite”:4865,“proto”:“h2”,“proto_mutual”:true,“server_name”:“mon.nomid.ws”}},“common_log”:“73.245.241.235 - - [13/Dec/2021:22:17:05 +0000] “GET / HTTP/2.0” 404 0”,“duration”:0.000242509,“size”:0,“status”:404,“resp_headers”:{“X-Robots-Tag”:[“noindex”],“Server”:[“Caddy”]}}
{“level”:“info”,“ts”:1639434827.3938856,“logger”:“http.log.access.log0”,“msg”:“handled request”,“request”:{“remote_addr”:“73.245.241.235:10351”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“mon.nomid.ws”,“uri”:"/",“headers”:{“Sec-Fetch-Site”:[“none”],“Sec-Fetch-User”:["?1"],“Te”:[“trailers”],“Accept”:[“text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8”],“Accept-Language”:[“en-US,ru;q=0.5”],“Dnt”:[“1”],“Upgrade-Insecure-Requests”:[“1”],“User-Agent”:[“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0”],“Accept-Encoding”:[“gzip, deflate, br”],“Sec-Fetch-Dest”:[“document”],“Sec-Fetch-Mode”:[“navigate”]},“tls”:{“resumed”:false,“version”:772,“cipher_suite”:4865,“proto”:“h2”,“proto_mutual”:true,“server_name”:“mon.nomid.ws”}},“common_log”:“73.245.241.235 - - [13/Dec/2021:22:33:47 +0000] “GET / HTTP/2.0” 0 0”,“duration”:0.000122822,“size”:0,“status”:0,“resp_headers”:{“Server”:[“Caddy”],“X-Robots-Tag”:[“noindex”]}}
{“level”:“info”,“ts”:1639434827.6388557,“logger”:“http.log.access.log0”,“msg”:“handled request”,“request”:{“remote_addr”:“73.245.241.235:10351”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“mon.nomid.ws”,“uri”:"/favicon.ico",“headers”:{“Referer”:[“https://mon.nomid.ws/"],“Sec-Fetch-Dest”:[“image”],“Sec-Fetch-Mode”:[“no-cors”],“Te”:[“trailers”],“User-Agent”:["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0”],“Accept-Language”:[“en-US,ru;q=0.5”],“Accept-Encoding”:[“gzip, deflate, br”],“Dnt”:[“1”],“Sec-Fetch-Site”:[“same-origin”],“Accept”:[“image/avif,image/webp,/”]},“tls”:{“resumed”:false,“version”:772,“cipher_suite”:4865,“proto”:“h2”,“proto_mutual”:true,“server_name”:“mon.nomid.ws”}},“common_log”:“73.245.241.235 - - [13/Dec/2021:22:33:47 +0000] “GET /favicon.ico HTTP/2.0” 0 0”,“duration”:0.000196214,“size”:0,“status”:0,“resp_headers”:{“Server”:[“Caddy”],“X-Robots-Tag”:[“noindex”]}}

5. What I already tried:

Different options in caddyfile, checked that containers see each other. Checked nginx config from monica CRM docker example - ```
https://raw.githubusercontent.com/monicahq/docker/master/.examples/nginx-proxy/web/nginx.conf


### 6. Links to relevant resources:
MonicaCRM FPM version uses nginx as web server. https://hub.docker.com/_/monica
I followed their guide except using caddy.
https://github.com/monicahq/docker/tree/master/.examples

The paths in the FPM container need to match the paths in the Caddy container. Basically, Caddy is telling FPM "hey, run this PHP script at /srv/monicacrm/index.php" but if that path doesn’t exist in the FPM container, it won’t know what to do.

I see, thank you for the tip.
I’ve changed the config files to account for the matching path, but it didn’t make the difference. I guess I’m missing something else.

  caddy:
    image: caddy:2
    container_name: caddy
    restart: always
#    networks:
#      - docker_default
#      - docker_dbnet_shared
    ports:
      - 80:80  # Needed for the ACME HTTP-01 challenge.
      - 443:443
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./caddy-config:/config
      - ./caddy-data:/data
      - ${DOCKER_APPDATA_PATH}/caddy/www:/srv
      - **${DOCKER_APPDATA_PATH}/caddy/www/monicacrm:/var/www/html/storage**
    environment:
      - EMAIL=some@email   # The email address to use for ACME registration.
      - LOG_FILE=/data/accesscaddy.log

Caddyfile

        root * /var/www/html/storage
        php_fastcgi 172.19.0.3:9000
        file_server

on the other hand, it appears as to Monica_CRM is unpacking the PHP application to public folder

sudo docker exec -it Monica_CRM ls -luah /var/www/html/public
total 76K
drwxr-xr-x 1 www-data www-data 4.0K Dec 14 22:43 .
drwxrwxrwx 1 www-data www-data 4.0K Dec 12 20:25 ..
-rw-r--r-- 1 www-data www-data 1.1K Nov 19 18:16 .htaccess
-rw-r--r-- 1 www-data www-data  13K Nov 19 18:16 changelog.json
drwxr-xr-x 2 www-data www-data 4.0K Dec 12 20:25 css
-rw-r--r-- 1 www-data www-data    0 Nov 19 18:16 favicon.ico
drwxr-xr-x 3 www-data www-data 4.0K Dec 12 20:25 fonts
drwxr-xr-x 3 www-data www-data 4.0K Dec 12 20:25 images
drwxr-xr-x 8 www-data www-data 4.0K Dec 12 20:25 img
-rw-r--r-- 1 www-data www-data 1.8K Nov 19 18:16 index.php
drwxr-xr-x 3 www-data www-data 4.0K Dec 12 20:25 js
-rw-r--r-- 1 www-data www-data  611 Nov 19 18:16 manifest.webmanifest
-rw-r--r-- 1 www-data www-data  451 Nov 19 18:17 mix-manifest.json
-rw-r--r-- 1 www-data www-data   24 Nov 19 18:16 robots.txt
-rw-r--r-- 1 www-data www-data   72 Nov 19 18:16 security.txt
lrwxrwxrwx 1 root     root       32 Dec 14 22:43 storage -> /var/www/html/storage/app/public
-rw-r--r-- 1 www-data www-data  914 Nov 19 18:16 web.config

But if I change root at the caddyfile to /var/www/html/public - still nothing good happends.

You should be mounting the contents of /var/www/html into the Caddy container, and setting your root to /var/www/html/public as that’s where the index.php entrypoint is.

1 Like

I had to copy contents of monica container www folder to host, and then mount it as volume to monica container and caddy container in the same path. This did the trick. But now I can’t get Caddy to communicate with monica docker container.
They are on different networks, this should be a problem, but I was under the impression docker handles the routing.

They need to be in the same network so that they can reach eachother.

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