Hello,
I have a website with a React frontend and a Laravel backend, using MariaDB as the database:
services:
# React Frontend
Frontend:
container_name: Frontend
build:
context: /home/Projects/frontend/
dockerfile: Dockerfile
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING="true"
- WATCHPACK_POLLING="true"
- NEXT_TELEMETRY_DISABLED=1
- MAX_OLD_SPACE_SIZE=4096
volumes:
- /home/Projects/frontend/:/app
- /app/node_modules
ports:
- "127.0.0.1:3000:3000"
deploy:
resources:
limits:
cpus: '4.0'
memory: 4G
# Laravel Backend
Backend:
build:
context: /home/Projects/backend
dockerfile: Dockerfile
container_name: Backend
entrypoint: ["/usr/local/bin/entrypoint.sh"]
command: ["php-fpm"]
network_mode: host
environment:
APP_ENV: local
APP_DEBUG: "true"
DB_HOST: host.docker.internal
DB_PORT: 3306
DB_DATABASE: laravel
DB_USERNAME: root
DB_PASSWORD: 123456
PORTAL_VIEW_URL: http://127.0.0.1:3000
volumes:
- /home/Projects/backend:/var/www
ports:
- "127.0.0.1:9000:9000"
extra_hosts:
- "host.docker.internal:host-gateway"
deploy:
resources:
limits:
cpus: '4.0'
memory: 4G
Due to some issues I am connecting to MariaDB on the host.
Nginx is installed on the host and its configuration is as follows:
server {
listen 80;
server_name localhost your-public-ip your-domain.com;
# Frontend React App
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Backend API
location /api {
# Remove try_files for API routes
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/public/index.php;
include fastcgi_params;
fastcgi_param HTTP_HOST $host;
fastcgi_param X-Real-IP $remote_addr;
fastcgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
# Add CORS headers
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'X-Requested-With,Content-Type,X-Token-Auth,Authorization' always;
# Handle preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'X-Requested-With,Content-Type,X-Token-Auth,Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
}
}
My website is slow and clicking on each menu takes a few seconds to go to the next page. What solution do you suggest? Is there something wrong with the Docker configuration?
Thank you.