我也遇到过同样的问题,
在我的测试中,我遇到了这两个问题:
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-certificates
我希望这对某人有所帮助,
如果有人对此有更多了解,请告诉我,
谢谢!