.htaccess?
Aug 22, 2023
3
Level 1
Laravel behind Nginx reverse proxy always throws 404
I have clean Laravel 10 app running in docker container using sails and nginx web server (in main server, not a docker container) with reverse proxy to Laravel app. No matter which path I try I always get 404 error. And this error is thrown from Laravel, not Nginx. I see Laravel's 404 template. That means my request reaches Laravel app but it throws 404 error somewhere in runtime. I tried disabling middlewares, but with no luck. If I open Laravel app directly, not through proxy, everything is fine. I know Laravel Sail should not be used in production, but I need this, don't ask why.
docker-compose.yml
version: "3"
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: "${WWWGROUP}"
image: sail-8.2/app
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "${APP_PORT:-80}:80"
- "${VITE_PORT:-5173}:${VITE_PORT:-5173}"
environment:
WWWUSER: "${WWWUSER}"
LARAVEL_SAIL: 1
XDEBUG_MODE: "${SAIL_XDEBUG_MODE:-off}"
XDEBUG_CONFIG: "${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}"
IGNITION_LOCAL_SITES_PATH: "${PWD}"
volumes:
- ".:/var/www/html"
networks:
- sail
networks:
sail:
driver: bridge
Nginx config
server {
listen 80;
server_name website.local;
client_max_body_size 32M;
location /admin/ {
access_log /var/log/nginx/admin_access.log;
error_log /var/log/nginx/admin_error.log;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://laravel.test:8080;
proxy_redirect off;
}
}
Any ideas what might be at fault?
Please or to participate in this conversation.