我有下一个docker-compose
文件:
nginx:
build: .
ports:
- "80:80"
- "443:443"
links:
- fpm
fpm:
image: php:fpm
ports:
- "9000:9000"
Dockerfile
命令列表是:
FROM nginx
ADD ./index.php /usr/share/nginx/html/
# Change Nginx config here...
Nginx服务器工作正常,我可以看到http://localhost/index.html
上的默认html页面,但不执行PHP脚本。所以当我得到http://localhost/index.php
时 - 浏览器下载PHP文件而不是执行它们。
在我的情况下,如何使用自定义Nginx配置来执行PHP脚本?
答案 0 :(得分:4)
您可以创建一个包含自定义nginx配置的非常简单的 docker 图像,并将此卷装入使用原始nginx图像的容器中。
只需几步即可。
mkdir -p nginxcustom/conf
cd nginxcustom
touch Dockerfile
touch conf/custom.conf
Dockerfile
这是文件内容:
FROM progrium/busybox
ADD conf/ /etc/nginx/sites-enabled/
VOLUME /etc/nginx/sites-enabled/
docker build -t nginxcustomconf .
docker-compose.yml
文件nginxcustomconf:
image: nginxcustomconf
command: true
nginxcustom:
image: nginx
hostname: nginxcustom
ports:
- "80:80"
- "443:443"
volumes_from:
- nginxcustomconf
示例conf/custom.conf
可能如下所示:
server {
listen 82;
server_name ${HOSTNAME};
set $cadvisor cadvisor.docker;
location / {
proxy_pass http://$cadvisor:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 16 64k;
proxy_busy_buffers_size 64k;
client_max_body_size 256k;
client_body_buffer_size 128k;
}
}