Caddy with Wordpress 404 on static assets

1. Output of caddy version:

v2.6.1 h1:EDqo59TyYWhXQnfde93Mmv4FJfYe00dO60zMiEt+pzo=

2. How I run Caddy:

a. System environment:

  • MacOS on M1
  • Docker (engine version 20.10.16 and compose version 1.29.2)

b. Command:

Standard command from the caddy container

c. Service/unit/compose file:

services:
  wordpress:
    image: wordpress:php8.1-fpm-alpine
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html
    depends_on:
      db:
        condition: service_healthy
    networks:
      - caddy

  caddy:
    image: caddy:2.6.1-alpine
    restart: unless-stopped
    ports:
      - "8080:8080"
      - "8081:8081"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
    networks:
      - caddy

  db:
    # We use a mariadb image which supports both amd64 & arm64 architecture
    image: mariadb:10.6.4-focal
    # If you really want to use MySQL, uncomment the following line
    #image: mysql:9.0.27
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    ports:
      - '3309:3306'
      - '33060:33060'
    networks:
      - caddy
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "--silent"]
      timeout: 10s
      retries: 20

networks:
  caddy:
    driver: bridge

volumes:
  db_data:
  wp_data:

d. My complete Caddy config:

localhost:8080 {
    root * /var/www/html
    encode gzip
    php_fastcgi wordpress:9000
    file_server
}

3. The problem I’m having:

I’m trying to setup Wordpress with Caddy, when I started the containers with docker-compose up -d everything is fine and I’m able to navigate to https://localhost:8080/wp-admin/install.php however the static assets (CSS & JS) that Wordpress is trying to retrieve return a 404 resulting in the page being unstyled.

4. Error messages and/or full log output:

Attempting to retrieve one of the files with curl -v gives the following output:

curl -v "https://localhost:8080/wp-includes/css/dashicons.min.css?ver=6.0.2"

*   Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Bypassing curl’s TLS verification with the -k flag for curl gives the following result:

curl -vk "https://localhost:8080/wp-includes/css/dashicons.min.css?ver=6.0.2"

*   Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
*  subject: [NONE]
*  start date: Oct 12 11:22:01 2022 GMT
*  expire date: Oct 12 23:22:01 2022 GMT
*  issuer: CN=Caddy Local Authority - ECC Intermediate
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x15b812400)
> GET /wp-includes/css/dashicons.min.css?ver=6.0.2 HTTP/2
> Host: localhost:8080
> user-agent: curl/7.77.0
> accept: */*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 404 
< alt-svc: h3=":8080"; ma=2592000
< server: Caddy
< content-length: 0
< date: Wed, 12 Oct 2022 11:32:45 GMT
< 
* Connection #0 to host localhost left intact

5. What I already tried:

I attempted to try with just HTTP by changing my Caddyfile to be

http://localhost:8080 {
    root * /var/www/html
    encode gzip
    php_fastcgi wordpress:9000
    file_server
}

However, this led to the same result.

6. Links to relevant resources:

Caddy needs access to the static files. this doesn’t work over the php_fastcgi directive.
You need to add the wpdata volume to the caddy container,

services:
  wordpress:
    image: wordpress:php8.1-fpm-alpine
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html
    depends_on:
      db:
        condition: service_healthy
    networks:
      - caddy

  caddy:
    image: caddy:2.6.1-alpine
    restart: unless-stopped
    ports:
      - "8080:8080"
      - "8081:8081"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      # mount the wordpress files into caddy
      - wp_data:/var/www/html
    networks:
      - caddy

  db:
    # We use a mariadb image which supports both amd64 & arm64 architecture
    image: mariadb:10.6.4-focal
    # If you really want to use MySQL, uncomment the following line
    #image: mysql:9.0.27
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    ports:
      - '3309:3306'
      - '33060:33060'
    networks:
      - caddy
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "--silent"]
      timeout: 10s
      retries: 20

networks:
  caddy:
    driver: bridge

volumes:
  db_data:
  wp_data:
4 Likes

That worked, thank you!

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