How to use normal Nginx config for official Dginx nginx image?

I have the following docker-compose

file:

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

      

List of commands Dockerfile

:

FROM nginx

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

# Change Nginx config here...

      

The Nginx server is working fine and I can see the default html page on http://localhost/index.html

, but not execute PHP scripts. So when I get http://localhost/index.php

- the browser downloads the PHP file rather than executing them.

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

+3


source to share


1 answer


You can create a very simple docker image containing your own nginx configuration and set that volume to a container that uses the original nginx image.

Just a few steps.

1. Create your own nginx config image project

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

      

2. Change Dockerfile

This is the content of the file:

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

      



3. Create a new image

docker build -t nginxcustomconf .

      

4. Modify the file docker-compose.yml

nginxcustomconf:
  image: nginxcustomconf
  command: true

nginxcustom:
  image: nginx
  hostname: nginxcustom
  ports:
    - "80:80"
    - "443:443"
  volumes_from:
    - nginxcustomconf

      

A sample conf/custom.conf

might look like this:

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;
  }
}

      

+3


source







All Articles