我一直有同样的问题,在我的测试中,我遇到了这两个问题:
1º:“找不到文件”
和
2º:404错误页面
我发现,就我而言:
我必须在 Nginx 卷和 PHP 卷上为我的公共文件夹安装卷。
如果它挂载在Nginx中并且没有挂载在PHP中,它会给出:“ File not found ”
示例(将显示“找不到文件错误”):
services:
php-fpm:
build:
context: ./docker/php-fpm
nginx:
build:
context: ./docker/nginx
volumes:
#Nginx Global Configurations
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/conf.d/:/etc/nginx/conf.d
#Nginx Configurations for you Sites:
# - Nginx Server block
- ./sites/example.com/site.conf:/etc/nginx/sites-available/example.com.conf
# - Copy Public Folder:
- ./sites/example.com/root/public/:/var/www/example.com/public
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
restart: always
如果它是挂载在PHP中而不是挂载在Nginx中,则会给出404 Page Not Found 错误。
示例(将抛出 404 Page Not Found 错误):
version: '3'
services:
php-fpm:
build:
context: ./docker/php-fpm
volumes:
- ./sites/example.com/root/public/:/var/www/example.com/public
nginx:
build:
context: ./docker/nginx
volumes:
#Nginx Global Configurations
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/conf.d/:/etc/nginx/conf.d
#Nginx Configurations for you Sites:
# - Nginx Server block
- ./sites/example.com/site.conf:/etc/nginx/sites-available/example.com.conf
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
restart: always
这可以正常工作(安装在两侧)(假设其他一切都配置良好并且您面临与我相同的问题):
version: '3'
services:
php-fpm:
build:
context: ./docker/php-fpm
volumes:
# Mount PHP for Public Folder
- ./sites/example.com/root/public/:/var/www/example.com/public
nginx:
build:
context: ./docker/nginx
volumes:
#Nginx Global Configurations
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/conf.d/:/etc/nginx/conf.d
#Nginx Configurations for you Sites:
# - Nginx Server block
- ./sites/example.com/site.conf:/etc/nginx/sites-available/example.com.conf
# - Copy Public Folder:
- ./sites/example.com/root/public/:/var/www/example.com/public
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
restart: always
这里还有一个使用 Nginx/Php 的完整工作示例项目,用于服务多个站点:
https ://github.com/Pablo-Camara/simple-multi-site-docker-compose-nginx-alpine-php-fpm-alpine-https -ssl 证书
我希望这对某人有所帮助,如果有人对此有更多了解,请告诉我,谢谢!