Reputation: 8563
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.
Upvotes: 0
Views: 102
Reputation: 10767
The problem is here:
volumes:
- .:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/web.conf:ro
NGINX comes with conf.d/default.conf. Since you are not deleting it, you should at least overwrite it:
volumes:
- .:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
Since you are not doing this, NGINX still load default.conf and that is why you see the default homepage.
An extra issue: when you do your mapping this way, your nginx.conf ends up in /var/www/html. Even if you don't serve this location in your conf file, I would still suggest to avoid doing this. You could map your volume like ./code:/var/www/html
. Even better, I would remove completely this mapping from the nginx service since it is not needed.
Upvotes: 1