目录结构
docker-compose.yml
version: "3.3"
services:
nginx:
image: nginx
ports:
- "8080:80"
links:
- php
volumes:
- ./www:/var/www/html
- ./nginx:/etc/nginx/conf.d
- ./log/nginx:/var/log/nginx
networks:
- webnet
php:
image: php:7.4-fpm
volumes:
- ./www:/var/www/html
networks:
- webnet
networks:
webnet:
nginx.conf
server {
listen 80;
server_name localhost;
index index.php index.html;
root /var/www/html;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
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;
}
}
index.php
<?php
phpinfo();
?>
之后启动镜像:
docker-compose up -d
访问网站:http://localhost:8080/