# How to setup caddy container for Nextcloud:fpm-alpine

**URL:** <https://help.nextcloud.com/t/how-to-setup-caddy-container-for-nextcloud-fpm-alpine/184230>\
**Category:** 📦 Appliances (Docker, Snappy, VM, NCP, AIO)\
**Tags:** caddy, podman\
**Created:** [March 3, 2024, 8:40pm UTC](https://help.nextcloud.com/t/how-to-setup-caddy-container-for-nextcloud-fpm-alpine/184230 "2024-03-03T20:40:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DevDorrejo](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devdorrejo/32/19501_2.png) [@DevDorrejo](https://help.nextcloud.com/u/DevDorrejo)\
**Post date:** [March 3, 2024, 8:40pm UTC](https://help.nextcloud.com/t/how-to-setup-caddy-container-for-nextcloud-fpm-alpine/184230/1 "2024-03-03T20:40:28Z")

</div>

Hello, i am trying to set up nextcloud:fpm-alpine in a pod rootless environment with podman, but i am not getting loock reaching it.

Here is the script to setup the enviromente:

```auto
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# shellcheck disable=SC1083

# Dependencies
zypper in -y podman systemd-container

# NAMES
USER_NAME="cloud"

if ! id -u "${USER_NAME}" &>/dev/null; then
    useradd -Uc "${USER_NAME} Daemon" -m "${USER_NAME}"
    loginctl enable-linger "${USER_NAME}"
fi

machinectl shell "${USER_NAME}"@

## Container Setup Database
# shellcheck disable=SC2016
cp -R /usr/share/containers "${HOME}"/.config/
sed -i '0,/"journald"/s,,"k8s-file",' "${HOME}"/.config/containers/containers.conf

# ================= #
# ===Environment=== #
# ================= #

POD_NAME="podCloud"
DB_NAME="pg-cloud"
CLOUD_NAME="cloud"
VOL="/opt/cloud"
NET="nextcloud"

podman rm -af --volumes && podman secret rm -a && podman volume prune -f && podman unshare rm -rf "${HOME}".enc/ /opt/cloud/* && podman network rm ${NET}

# =================== #
# ===Miscellaneous=== #
# =================== #

# Secret Setup
mkdir -m 700 "${HOME}"/.enc
openssl rand -base64 32 >"${HOME}"/.enc/pgpass
PGSECRET=$(podman secret create pgpass "${HOME}"/.enc/pgpass)
openssl rand -base64 32 >"${HOME}"/.enc/pgapp
PGAPPSECRET=$(podman secret create pgapp "${HOME}"/.enc/pgapp)
# CLOUDSECRET=$(openssl rand -base64 32 | podman secret create pgsecret -)

# ============= #
# ===Volumes=== #
# ============= #

# Cloud Management
folders=(
    "html"
    "config"
    "data"
)

paths="${VOL}/cloud"
for d in "${folders[@]}"; do
    if [! -d "${paths}/${d}"]; then
        mkdir -p "${paths}/${d}"
    fi
    podman volume create \
        -o type=none \
        -o device="${paths}/${d}" \
        -o o=bind \
        "${d}"
done

# DB Management
folders=(
    "pgdata"

)

paths="${VOL}/pgdb"
for d in "${folders[@]}"; do
    if [! -d "${paths}/${d}"]; then
        mkdir -p "${paths}/${d}"
    fi
    podman volume create \
        -o type=none \
        -o device="${paths}/${d}" \
        -o o=bind \
        "${d}"
done

# Caddy Management
folders=(
    "caddy_data"
    "caddy_config"
    "caddy_etc"
    "caddy_log"
)

paths="${VOL}/caddy"
for d in "${folders[@]}"; do
    if [! -d "${paths}/${d}"]; then
        mkdir -p "${paths}/${d}"
    fi
    if ! podman volume inspect "${d}" &>/dev/null; then
        podman volume create \
            -o type=none \
            -o device="${paths}/${d}" \
            -o o=bind \
            "${d}"
    fi
done

# ============= #
# ===Network=== #
# ============= #

podman network create "${NET}"

# =============== #
# ===POD_Cloud=== #
# =============== #

podman pod create \
    --replace \
    --restart unless-stopped \
    --network "${NET}" \
    -n "${POD_NAME}" \
    -p 8080:80 \
    -v pgdata:/data/postgresql \
    -v html:/var/www/html \
    -v config:/var/www/html/config \
    -v data:/opt/data \
    -v caddy_data:/data \
    -v caddy_config:/config \
    -v caddy_etc:/etc/caddy \
    -v caddy_log:/var/log/caddy

# ========================= #
# ===Database_PostgreSQL=== #
# ========================= #

# pgSQL_Apps Container
podman run -d \
    --pod podCloud \
    --replace \
    --pull=newer \
    --label "io.containers.autoupdate=registry" \
    --restart unless-stopped \
    --name "${DB_NAME}" \
    --secret "${PGSECRET}" \
    -e PGDATA=/data/postgresql \
    -e POSTGRES_PASSWORD=/var/run/"$(podman secret inspect --format {{.Spec.Name}} "${PGSECRET}" | grep -vE "^$")" \
    docker.io/postgres:latest

sleep 20s
podman exec -it -u postgres "${DB_NAME}" psql -c "CREATE USER cloud WITH PASSWORD '$(podman secret inspect --format {{.SecretData}} --showsecret "${PGAPPSECRET}" | grep -vE "^$")';" &&
    podman exec -it -u postgres "${DB_NAME}" psql -c "CREATE DATABASE cloud OWNER cloud;" &&
    podman exec -it -u postgres "${DB_NAME}" psql -c "GRANT ALL PRIVILEGES ON DATABASE cloud TO cloud;"

# =============== #
# ===NextCloud=== #
# =============== #

podman run -d \
    --pod podCloud \
    --replace \
    --pull newer \
    --label "io.containers.autoupdate=registry" \
    --restart unless-stopped \
    --name "${CLOUD_NAME}" \
    --secret "${PGSECRET}" \
    -e POSTGRES_DB=cloud \
    -e POSTGRES_USER=cloud \
    -e POSTGRES_PASSWORD=/var/run/"$(podman secret inspect --format {{.Spec.Name}} "${PGSECRET}" | grep -vE "^$")" \
    -e POSTGRES_HOST=localhost \
    -e NEXTCLOUD_DATA_DIR=/opt/data \
    -e NEXTCLOUD_TRUSTED_DOMAINS=contraProcuratorem \
    -e NEXTCLOUD_INIT_HTACCESS=true \
    -e PHP_MEMORY_LIMIT=1024M \
    -e APACHE_DISABLE_REWRITE_IP=1 \
    docker.io/nextcloud:fpm-alpine

# ================ #
# ===Rev. Proxy=== #
# ================ #

cat >"$paths/${folders[2]}"/Caddyfile <<EOF
{
    # Server Options
    auto_https off
}

* {
    reverse_proxy ${CLOUD_NAME}:9000
    log {
        output file /var/log/caddy/cloud.log
        level ERROR
    }
}
EOF

podman run -d \
    --pod podCloud \
    --replace \
    --pull=newer \
    --restart unless-stopped \
    --label "io.containers.autoupdate=registry" \
    --cap-add=NET_ADMIN \
    --name contraProcuratorem \
    docker.io/caddy:latest

podman logs -f contraProcuratorem

```

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [March 4, 2024, 12:47pm UTC](https://help.nextcloud.com/t/how-to-setup-caddy-container-for-nextcloud-fpm-alpine/184230/2 "2024-03-04T12:47:45Z")

</div>

Please take a look at this guide:

> [@Tutorial for running Nextcloud in rootless Podman with mariadb, redis, caddy webserver , all behind a caddy reverse proxy](https://help.nextcloud.com/t/tutorial-for-running-nextcloud-in-rootless-podman-with-mariadb-redis-caddy-webserver-all-behind-a-caddy-reverse-proxy/159216):
>
> Hi Everyone, Hopefully I can help a few users that are trying to run Nextcloud using Podman, behind a Caddy reverse proxy, for a while I struggled to get it working properly but after a lot of research and help from threads in this forum, I finally have Nextcloud working perfectly. So I run all my containers from Home assistant to Nextcloud in Rootless Podman and I love it , I run each container using systemd unit files rather than Podman compose or docker compose, this has the added benefit o…

---

<div class="post-metadata">

**Author:** ![DevDorrejo](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devdorrejo/32/19501_2.png) [@DevDorrejo](https://help.nextcloud.com/u/DevDorrejo)\
**Post date:** [March 4, 2024, 2:59pm UTC](https://help.nextcloud.com/t/how-to-setup-caddy-container-for-nextcloud-fpm-alpine/184230/3 "2024-03-04T14:59:49Z")

</div>

Thanks, but not working when setting the domain, here is a update of the script, is more functional, but when a domain is assigned to the caddy it would not load the nextcloud, or nextcloud wont response correctly:

> **[Nextcloud:fpm-alpine Rootless - Pastebin.com](https://pastebin.com/Xyav6HPk)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [March 4, 2024, 5:10pm UTC](https://help.nextcloud.com/t/how-to-setup-caddy-container-for-nextcloud-fpm-alpine/184230/4 "2024-03-04T17:10:59Z")

</div>

I’m sorry I’m not going to troubleshoot your rather complex script.

Please isolate a problem and provide the smallest example you can reproduce the issue so we can find the reason. I would recommend you start with simple working example and add complexity step by step until it brakes.

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [January 16, 2025, 8:40am UTC](https://help.nextcloud.com/t/how-to-setup-caddy-container-for-nextcloud-fpm-alpine/184230/5 "2025-01-16T08:40:21Z")

</div>


