I am having issues with my docker-compose
to point the nginx
container to serve the directory ${APP_CONTAINER_DIR}
from my app
container
right now, connecting to 127.0.0.1:8000 I get nginx error 404; I am guessing it is not finding the files since I have no error in the nginx logs
I think the problem comes from root /var/www/app/public;
in dev.conf but not sure how to do it; I tried app:root /var/www/app/public;
but this is not working
here is my docker-compose
version: "3"
services:
nginx:
container_name: nginx
image: "${NGINX_IMAGE}"
build: build/nginx
restart: 'always'
env_file: .env
ports:
- "8000:443"
volumes:
- "./build/nginx/build/dev.conf:/etc/nginx/conf.d/default.conf:ro"
- "./build/nginx/build/certs:/etc/nginx/certs"
networks:
- app_network
depends_on:
- app
app:
container_name: app
image: "${APP_IMAGE}"
restart: always
build: build/app
env_file: .env
volumes:
- "${APP_HOST_DIR}:${APP_CONTAINER_DIR}"
depends_on:
- database
networks:
- app_network
database:
container_name: mariadb
image: "mariadb:${MARIADB_VERSION}"
restart: 'always'
env_file: .env
volumes:
- "${SQL_INIT}:/docker-entrypoint-initdb.d"
- "db_data:${MARIADB_DATA_DIR}"
- "db_logs:${MARIADB_LOG_DIR}"
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_DATABASE: "${MYSQL_DATABASE}"
MYSQL_USER: "${MYSQL_USER}"
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
ports:
- "3306:3306"
networks:
- app_network
volumes:
db_data:
db_logs:
networks:
app_network:
dev.conf
#./images/nginx/build/default.conf
server {
listen 443 ssl;
server_name 127.0.0.1;
ssl_certificate /etc/nginx/certs/dev.crt;
ssl_certificate_key /etc/nginx/certs/dev.key;
index index.php index.html;
root /var/www/app/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
error_log /var/log/nginx/app.error.log;
access_log /var/log/nginx/app.access.log;
}
.env
APP_HOST_DIR=./app
APP_CONTAINER_DIR=/var/www/app/
2
Answers
You should go with the given folder mounted inside nginx docker.
If there is some dynamic files/content that the app is generating, you should also mount the same host folder in app docker container.
Your docker-compose.yml is not complete, you have to mount the path
/var/www/app/public
to your php-code, e.g.- "./${APP_HOST_DIR}:/var/www/app/public:ro"
.Furthermore you should remove the variable $APP_CONTAINER_DIR in favor of the configured path
/var/www/app/public
.So your file should look like this: