How to reverse proxy frankenphp #718
-
|
I have both my development and production environments running on a single Digital Ocean droplet, using a Frankenphp image. To ensure the correct application is served, I've implemented Caddy. Since Caddy handled SSL certificate creation, I disabled it within the Frankenphp image by setting SERVER_NAME: :80 in the compose.yaml file. When I visited example.com, it correctly displayed the Laravel default page, which was a good sign. However, when I attempted to log in, the styling failed to load because the CSS and JavaScript files were being served over HTTP internally. Browsers like Google Chrome don't allow this behavior. I attempted to resolve this issue by adding a global directive to the Caddyfile of my Caddy image, as suggested in the documentation. Unfortunately, this didn't work as expected. I also consulted the Caddy config documentation, but either my implementation was incorrect, or I misunderstood the instructions. Does anyone have an idea on how to resolve this issue? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 16 replies
-
|
CSS and JS urls is not a caddy issue, but something with your configuration and/or app code |
Beta Was this translation helpful? Give feedback.
-
|
I have the same problem. It seems it is an impossible mission... so frustrating. I spent long hours to handle this problem this. (3rd time... it is around net 19 hours) And ZERO success. 😆 It seems, my 15+ years of experience is not enough to set up a single Symfony-MariaDB-FrankenPHP config under reverse proxy. So sad. Although, this is just further proof that I am more of a developer than a devops. The FrankenPHP seems a very good project and idea but under reverse proxy it is real impossible to configure. I maintain 12 projects but I can run only 2 of them w/ FPHP, because they can be reached through the VPS and wired directly to the FrankenPHP container. All others should be run under reverse proxy. Anyway, I would share my config, if a miracle happens, and there is a genius who can find my failure through them. Please do not hesitate to educate me. I would like to share the most relevant parts. Rant is over. This is an old (old but not legacy, React v19, PHP 8.4.* and Symfony 7.2.*) project, and I have a CI/CD script (Gitea Actions) for releasing it. I would be soooo good to use under FrankenPHP. (And the other 12 projects) My FrankenPHP's My Symfony's .env file Projects FROM dunglas/frankenphp:1
COPY . /app
COPY --link bin/docker/Caddyfile /etc/caddy/Caddyfile
RUN cp $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
RUN cp bin/docker/php.ini-production $PHP_INI_DIR/conf.d/custom-php.ini
RUN install-php-extensions \
@composer \
pdo_mysql \
gd \
mbstring \
bcmath \
intl \
zip \
opcache \
apcu \
iconv
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV APP_RUNTIME=Runtime\\FrankenPhpSymfony\\Runtime
ENV FRANKENPHP_CONFIG="worker ./public/index.php"The Docker's compose.yaml services:
db:
# @see https://hub.docker.com/_/mariadb
image: mariadb:11.7.2
restart: always
healthcheck:
test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized" ]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3
container_name: '${APP_NAME}-db'
environment:
- MARIADB_ROOT_PASSWORD=${DATABASE_PASSWORD:-!ChangeMe!}
- MARIADB_DATABASE=${DATABASE_DB:-app}
- MARIADB_USER=${DATABASE_USER:-app}
- MARIADB_PASSWORD=${DATABASE_PASSWORD:-!ChangeMe!}
ports:
- "7306:3306"
volumes:
- database:/var/lib/mysql:rw
networks:
- natur_api_network
api:
# @see https://source.splendidbear.org/NaturAgro/api
# @see https://hub.docker.com/r/dunglas/frankenphp
image: dunglas/frankenphp:1-alpine
build: .
restart: always
container_name: '${APP_NAME}-app'
environment:
- APP_DOMAIN=${APP_DOMAIN}
- MERCURE_PUBLISHER_JWT_KEY={$MERCURE_PUBLISHER_JWT_KEY}
- MERCURE_SUBSCRIBER_JWT_KEY={$MERCURE_SUBSCRIBER_JWT_KEY}
ports:
- "7080:80"
- "7443:443"
- "7443:443/udp"
volumes:
- ./:/app
- /var/storage/storage:/app/public/storage
- caddy_data:/data
- caddy_config:/config
depends_on:
db:
condition: service_healthy
networks:
- natur_api_network
volumes:
caddy_data:
caddy_config:
database:
networks:
natur_api_network:This is the host's |
Beta Was this translation helpful? Give feedback.
-
|
I was stressed for like 6 hours because of the Caddyfile setup. Uploading files in my Filament app kept failing with a 401 error, even though it works fine in my local development. So, here’s my Caddyfile setup and a working Docker Compose for anyone who wants to set up Apache2 + FrankenPHP + Filament Laravel. Caddyfile then run docker compose up and I think now is working, Thanks for this discussion! |
Beta Was this translation helpful? Give feedback.
Heh. It isn't. I could probably write a book about the problem you are stuck on, and we have all been stuck on some version of this problem. I don't want to spoil it for you because it's a good learning experience for how the web works... but I will give you a direction.
I recommend reading up on https://laravel.com/docs/11.x/urls and note:
So you need to figure out one of two options: