如何正确链接php-fpm和Nginx Docker容器?
我正在尝试链接 2 个单独的容器:
问题是php脚本不起作用。也许 php-fpm 配置不正确。这是源代码,在我的存储库中。这是文件:docker-compose.yml
nginx:
build: .
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www/test/
links:
- fpm
fpm:
image: php:fpm
ports:
- "9000:9000"
我用它来构建基于nginx的自定义映像:Dockerfile
FROM nginx
# Change Nginx config here...
RUN rm /etc/nginx/conf.d/default.conf
ADD ./default.conf /etc/nginx/conf.d/
最后,这是我的自定义Nginx虚拟主机配置:
server {
listen 80;
server_name localhost;
root /var/www/test;
error_log /var/log/nginx/localhost.error.log;
access_log /var/log/nginx/localhost.access.log;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass 192.168.59.103:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
任何人都可以帮我正确配置这些容器以执行php脚本吗?
附言我通过 docker-composer 运行容器,如下所示:
docker-compose up
从项目根目录。