我有下一个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配置的docker映像,并将此卷安装在使用原始Nginx映像的容器中.
原文链接:/nginx/532442.html仅需遵循几个步骤.
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 .
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;
}
}