App shows 502 status

I deployed Nextcloud using the official Docker image. I used the following (relatively straightforward) script to do it:

if ! flyctl redis list | grep "msr-bucket-redis" &>/dev/null; then
  flyctl redis create \
    --name msr-bucket-redis \
    --plan Free \
    --region lax \
    --no-replicas \
    --disable-eviction >redis.txt

if ! flyctl postgres list | grep "msr-bucket-postgres" &>/dev/null; then
  flyctl postgres create \
    --name msr-bucket-postgres \
    --initial-cluster-size 1 \
    --vm-size shared-cpu-1x \
    --volume-size 1 \
    --region lax >postgres.txt

if ! flyctl apps list | grep "msr-bucket-nextcloud" &>/dev/null; then
  flyctl launch \
    --name msr-bucket-nextcloud \
    --region lax \
  rm fly.toml
  flyctl postgres attach \
    msr-bucket-postgres \
    --app msr-bucket-nextcloud \
    --database-user nextcloud \
    --database-name nextcloud \
    --force >db.txt

# set some app secrets

flyctl deploy \
  --app msr-bucket-nextcloud \
  --image nextcloud \

App is deployed at, and currently showing 502 status after waiting for couple of minutes in loading state. Can anyone guide me to how I can fix it please? Thanks in advance.

Maybe it’s because the underlying proxy server doesn’t know where to forward the incoming HTTP requests.