#Laravel 12 + Inertia in Docker, reverse proxy impossible?

6 messages · Page 1 of 1 (latest)

livid fulcrum
#

Hi, first timer on discord but not for laravel, I've installed and configured the new Laravel 12 React starter kit with Inertia. I've 0 customization on it, literally just the starter kit.
I created a bunch of Dockerfile to host my app, here's the first one for nginx container

FROM registry.gitlab.com/custom/company/registry/composer:latest AS installer

WORKDIR /var/www

COPY ./composer.json .
COPY ./composer.lock .

RUN composer install \
    --no-interaction \
    --no-plugins \
    --no-scripts \
    --no-dev \
    --prefer-dist \
    --ignore-platform-req=*

FROM registry.gitlab.com/custom/company/registry/php:8.4 AS linker

WORKDIR /var/www

COPY . .

RUN php artisan storage:link

FROM registry.gitlab.com/custom/company/registry/nginx:1.2

WORKDIR /var/www

COPY .env ./.env
COPY --from=linker /var/www .
COPY --from=installer /var/www/vendor .

RUN chown -R www-data:www-data \
    ./app \
    ./bootstrap \
    ./config \
    ./database \
    ./public \
    ./resources \
    ./routes \
    ./storage \
    ./vendor \
    ./composer.json \
    ./composer.lock \
    ./.env \
    ./artisan \
    && chmod 775 -R storage/framework/cache \
    && chmod 775 -R bootstrap/cache \
    && chgrp www-data -R storage/framework/cache \
    && rm -rf /usr/share/php /tmp/* /var/cache/apt/* \
    && rm -rf /var/lib/apt/lists/*

[Continue...]

#

The second one is for php, doesn't change much

FROM registry.gitlab.com/custom/company/registry/php:8.4

ENV OPCACHE_JIT_FLAGS=1225

WORKDIR /var/www

COPY . .
COPY .env ./.env

RUN composer install \
    --no-interaction \
    --no-plugins \
    --no-scripts \
    --no-dev \
    --prefer-dist \
    && chown -R www-data:www-data \
    ./app \
    ./bootstrap \
    ./config \
    ./database \
    ./public \
    ./resources \
    ./routes \
    ./storage \
    ./vendor \
    ./composer.json \
    ./composer.lock \
    ./.env \
    ./artisan \
    && chmod 775 -R storage/framework/cache \
    && chmod 775 -R bootstrap/cache \
    && chgrp www-data -R storage/framework/cache \
    && php artisan storage:link \
    && rm -rf /usr/share/php /tmp/* /var/cache/apt/* \
    && rm -rf /var/lib/apt/lists/*

Then this is the docker-compose used in production

name: inertiaDemo

services:
  nginx:
    image: registry.gitlab.com/project/repository/nginx:production
    container_name: demo_nginx
    restart: unless-stopped
    ports:
      - "127.0.0.1:8899:80"
    volumes:
      - socket:/var/run/socket
      - ./logs/nginx:/var/log/nginx
    networks:
      - demos

  app:
    image: registry.gitlab.com/project/repository/php:production
    container_name: demo_app
    restart: unless-stopped
    volumes:
      - socket:/var/run/socket
      - ./storage:/var/www/storage/app
      - ./logs/application:/var/www/storage/logs
    networks:
      - demos

volumes:
  socket:

networks:
  demos:
    name: demos

The machine that host the containers has Caddy as reverse proxy, this is the configuration for this particular demo

demo-inertia.company.example {
   reverse_proxy 127.0.0.1:8899
}

[Continue...]

livid fulcrum
#

Now the issue is that every link/form submissions i get the usual white modal with the message All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.

The strange part is that it works locally but it's not dockerized of course

Does anybody have a clue on why it doesn't work?

Things to consider:

  • Nginx container has a default .conf file
  • PHP container is the vanilla one we just use our registry
proper junco
#

Which cloud/service are you using that allows/facilitates "docker compose" in production deployments?

livid silo
proper junco