如何使用自定义Nginx配置官方的nginx Docker映像? [英] How to use custom Nginx config for official nginx Docker image?

查看:231
本文介绍了如何使用自定义Nginx配置官方的nginx Docker映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个 docker-compose 文件:

nginx:
    build: .
    ports:
        - "80:80"
        - "443:443"
    links:
        - fpm
fpm:
    image: php:fpm
    ports:
        - "9000:9000"

code> Dockerfile 命令列表是:

The Dockerfile command list is:

FROM nginx

ADD ./index.php /usr/share/nginx/html/

# Change Nginx config here...

Nginx服务器工作正常,我可以在 http://localhost/index.html 上看到默认的html页面, t执行PHP脚本。所以当我得到 http://localhost/index.php - 浏览器下载PHP文件而不是执行它们。

The Nginx server work fine and I can see default html page on http://localhost/index.html, but don't execute PHP scripts. So when I get http://localhost/index.php - browser download PHP file instead of execute them.

如何使用自定义Nginx配置在我的情况下执行PHP脚本?

How can I use custom Nginx config to execute PHP script in my case?

推荐答案

您可以创建一个非常简单的包含您的自定义nginx配置的docker 图像,并将此卷装载到使用原始nginx映像的容器中。

You can create a very simple docker image containing your custom nginx configuration and mount this volume in the container that uses original nginx image.

只需几个步骤即可。

mkdir -p nginxcustom/conf
cd nginxcustom
touch Dockerfile
touch conf/custom.conf



2。修改 Dockerfile



这是文件内容:

2. Modify Dockerfile

This is the file content:

FROM progrium/busybox
ADD conf/ /etc/nginx/sites-enabled/
VOLUME /etc/nginx/sites-enabled/



3。构建新图像



3. Build the new image

docker build -t nginxcustomconf .



4。修改您的 docker-compose.yml 文件



4. Modify your docker-compose.yml file

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配置官方的nginx Docker映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆