get nginx to play nicely with php-fpm in docker
I am trying to setup docker with nginx and php-fpm but it seems like there’s something going wrong with regards to nginx conf (I don’t know what exactly).
Here’s docker-compose.yml
version: '3.3'
services:
php:
image: php:7.1-fpm
volumes:
- .:/var/www/html
working_dir: /var/www/html
networks:
- web
nginx:
image: nginx
depends_on:
- php
working_dir: /var/www/html
volumes:
- .:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/web.conf:ro
ports:
- 8000:80
networks:
- web
networks:
web:
nginx.conf
server {
listen 80 default_server;
server_name localhost;
index index.php index.html;
root /var/www/html/code;
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
./code/index.php
<?php phpinfo(); ?>
And then on the terminal
docker-compose up -d
I don’t understand what I am doing wrong here but when I visit http://localhost:8000
I get the nginx welcome page instead of what’s within code/index.php
.
Can anyone help? Thanks
P.S: I am running the latest docker desktop on a mac.
Source: StackOverflow