1 回答

TA貢獻1793條經驗 獲得超6個贊
您需要為 PHP 和 Nginx docker 鏡像安裝相同的卷。
version: '3'
services:
nginx:
image: nginx:alpine
volumes:
- ./app:/app
- ./nginx-config/:/etc/nginx/conf.d/
ports:
- 80:80
depends_on:
- php
php:
image: php:7.3-fpm-alpine
volumes:
- ./app:/app
在上面的撰寫文件中,代碼放置app在主機的文件夾下。
樹
├── app
│ ├── helloworld.php
│ └── index.php
├── docker-compose.yml
└── nginx-config
└── default.conf
您的 Nginx 配置應該使用 docker 服務網絡來連接 php-fpm 容器。
server {
index index.php index.html;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /app/;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
或者你可以嘗試 Github 上的工作示例。
git clone https://github.com/Adiii717/dockerize-nginx-php.git
cd dockerize-nginx-php;
docker-compose up
現在打開瀏覽器
http://localhost/helloworld.php
- 1 回答
- 0 關注
- 150 瀏覽
添加回答
舉報