У меня есть приложение nuxt.js
с laravel
API. Все работает в docker
. Вы можете проверить мою конфигурацию здесь https://github.com/niqitos/laravel-nuxt-docker. Приложение Nuxt - это папка /client
и laravel API в /api
.
docker -compose.yml
version: '3'
######### Services ###################################
services:
# Server container
nginx:
build:
context: docker/nginx
dockerfile: Dockerfile
volumes:
- ./:/var/www
- ./docker/nginx/logs:/var/log/nginx
ports:
# Nuxt port
- 80:80
# Laravel port
- 8081:81
links:
- node
- php-fpm
# PHP FastCGI Process Manager container
php-fpm:
build:
context: docker/php-fpm
dockerfile: Dockerfile
volumes:
- ./api:/var/www/api
environment:
# If you down want to use xDebug, set remote_enable=0
XDEBUG_CONFIG: "remote_enable=1"
PHP_IDE_CONFIG: "serverName=Docker"
links:
- postgres
- redis
expose:
- 81
labels:
traefik.frontend.rule: PathPrefixStrip:/api
traefik.port: 81
# Supervisor container (schedule and queue runner)
supervisor:
build:
context: docker/supervisor
dockerfile: Dockerfile
volumes:
- ./:/var/www/
- ./docker/supervisor/conf.d:/etc/supervisor/conf.d
- ./docker/supervisor/logs:/var/log
links:
- postgres
- redis
# Node container
node:
build:
context: docker/node
dockerfile: Dockerfile
volumes:
- ./client:/var/www/client
expose:
- 80
environment:
NUXT_HOST: 0.0.0.0
API_URL: http://nginx:80/api/
CLIENT_URL: http://localhost:80
GOOGLE_MAPS_API_KEY:
labels:
traefik.frontend.rule: PathPrefixStrip:/
traefik.port: 80
# PostgreSQL database container
postgres:
build:
context: docker/postgres
dockerfile: Dockerfile
volumes:
# Database volume
- database:/var/lib/postgresql/data
# Temp volume to allow using dumps
- ./docker/postgres/dumps/:/tmp/
ports:
- 5432:5432
environment:
- LC_ALL=C.UTF-8
- POSTGRES_DB=app
- POSTGRES_USER=app
- POSTGRES_PASSWORD=app
# Redis container
redis:
build:
context: docker/redis
dockerfile: Dockerfile
volumes:
- redis:/data
- ./docker/redis/redis.conf:/data/redis.conf
ports:
- 6379:6379
# Node command line container
node-cli:
build:
context: docker/node-cli
dockerfile: Dockerfile
volumes:
- ./client:/var/www/client
tty: true
# PHP Command line container
php-cli:
build:
context: docker/php-cli
dockerfile: Dockerfile
volumes:
- ./api:/var/www/api
environment:
# If you down want to use xDebug, set remote_enable=0
XDEBUG_CONFIG: "remote_enable=1"
PHP_IDE_CONFIG: "serverName=Docker"
links:
- postgres
- redis
tty: true
proxy:
build:
context: docker/php-cli
dockerfile: Dockerfile
command: --docker
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
elasticsearch:
build:
context: docker/elasticsearch
dockerfile: Dockerfile
volumes:
- ./docker/elasticsearch/data:/usr/share/elasticsearch/data
environment:
- node.name=elasticsearch
- discovery.seed_hosts=elasticsearch
- cluster.initial_master_nodes=elasticsearch
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- 9200:9200
######### Volumes ###################################
volumes:
database:
driver: local
redis:
driver: local
docker / nginx / default.conf
#--------------------------------------------------------
# Nuxt.JS server configuration
#--------------------------------------------------------
map $sent_http_content_type $expires {
"text/html" epoch;
"text/html; charset=utf-8" epoch;
default off;
}
server {
listen 80;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
charset utf-8;
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
location / {
# Proxy to Node.JS instance
proxy_pass http://node:3000;
expires $expires;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
# Websocket support
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 all API requests
location /api {
proxy_pass http://nginx:81;
}
}
#--------------------------------------------------------
# Laravel server configuration
#--------------------------------------------------------
server {
#listen 443 ssl;
listen 81;
index index.php index.html;
root /var/www/api/public;
charset utf-8;
client_max_body_size 20m;
# SSL for 443
#ssl_certificate /etc/nginx/ssl/ssl-cert-snakeoil.pem;
#ssl_certificate_key /etc/nginx/ssl/ssl-cert-snakeoil.key;
location / {
try_files $uri $uri/ /index.php?$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
# Handle all php files (which will always be just /index.php)
# via factcgi PHP-FPM unix socket
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
# For comfortable debugging
fastcgi_read_timeout 1000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Я хочу добавить еще одно приложение. js для администратора в папке /admin
. Но я не могу обернуться вокруг этого уже неделю. Все попытки заканчиваются ошибками при сборке. Что я должен добавить в docker-compose.yml
и nginx
config?