php-如何使用自定义Nginx配置作为官方Nginx Docker镜像?
作者:互联网
我有下一个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脚本?
解决方法:
您可以创建一个非常简单的包含自定义nginx配置的docker映像,并将此卷安装在使用原始nginx映像的容器中.
仅需遵循几个步骤.
1.创建自定义的nginx配置映像项目
mkdir -p nginxcustom/conf
cd nginxcustom
touch Dockerfile
touch conf/custom.conf
2.修改Dockerfile
这是文件内容:
FROM progrium/busybox
ADD conf/ /etc/nginx/sites-enabled/
VOLUME /etc/nginx/sites-enabled/
3.建立新形象
docker build -t nginxcustomconf .
4.修改您的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;
}
}
标签:nginx,docker,docker-compose,dockerfile,php 来源: https://codeday.me/bug/20191028/1952209.html