I have next docker-compose
file:
nginx:
build: .
ports:
- "80:80"
- "443:443"
links:
- fpm
fpm:
image: php:fpm
ports:
- "9000:9000"
The Dockerfile
command list is:
FROM nginx
ADD ./index.php /usr/share/nginx/html/
# Change Nginx config here...
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.
How can I use custom Nginx config to execute PHP script in my case?
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.
There are just a few steps to follow.
mkdir -p nginxcustom/conf
cd nginxcustom
touch Dockerfile
touch conf/custom.conf
Dockerfile
This is the file content:
FROM progrium/busybox
ADD conf/ /etc/nginx/sites-enabled/
VOLUME /etc/nginx/sites-enabled/
docker build -t nginxcustomconf .
docker-compose.yml
filenginxcustomconf:
image: nginxcustomconf
command: true
nginxcustom:
image: nginx
hostname: nginxcustom
ports:
- "80:80"
- "443:443"
volumes_from:
- nginxcustomconf
The sample conf/custom.conf
may 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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With