【发布时间】:2022-01-17 22:23:27
【问题描述】:
我的docker-compose 有问题,无法将nginx 容器指向我的app 容器中的${APP_CONTAINER_DIR} 目录
现在,连接到 127.0.0.1:8000 我得到 nginx 错误 404;我猜它没有找到文件,因为我在 nginx 日志中没有错误
我认为问题来自 dev.conf 中的root /var/www/app/public;,但不知道该怎么做;我试过 app:root /var/www/app/public; 但这不起作用
这是我的 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/
【问题讨论】:
-
你有没有 bash 进入你的 ./app 目录来检查容器内是否有公共目录?
-
@Soheb 是的,我在这个位置有 index.php
-
您可以尝试将
:ro从./build/nginx/build/dev.conf:/etc/nginx/conf.d/default.conf:ro行的末尾删除到./build/nginx/build/dev.conf:/etc/nginx/conf.d/default.conf我知道文档中提到了它,但请尝试让我知道是否有帮助 -
@Soheb 我已经试过了;没有帮助
-
链接的问题几乎涵盖了所有替代方案:让应用程序提供自己的静态文件,将静态资产复制到反向代理映像中,或围绕共享命名卷的几种方法。
标签: docker nginx docker-compose