I'm trying to set up Symfony 3 in Docker on a Windows machine with NGINX and PHP-FPM. At the moment, I get a 502 bad gateway error. I changed the FPM port from 9000 to 8000 because on my host, port 9000 is already in use by a hyper-v service vmms.exe. I don't know if it's related.
docker-compose.yml
version: "3"
services:
nginx:
build: ./nginx
volumes:
- ./symfony:/usr/shared/nginx/html
ports:
- "80:80"
- "443:443"
environment:
- NGINX_HOST=free-energy.org
depends_on:
- fpm
fpm:
image: php:fpm
ports:
- "8000:8000"
# It seems like FPM receives the full path from NGINX
# and tries to find the files in this dock, so it must
# be the same as nginx.root
volumes:
- ./symfony:/usr/shared/nginx/html
Dockerfile NGINX:
FROM nginx:1.13.7-alpine
# Change Nginx config here...
RUN rm /etc/nginx/conf.d/default.conf
ADD ./default.conf /etc/nginx/conf.d/
EXPOSE 80
EXPOSE 443
default.conf override NGINX:
server {
listen 80;
server_name free-energy.org;
# this path MUST be exactly as docker-compose.fpm.volumes,
# even if it doesn't exist in this dock.
root /usr/share/nginx/html;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass fpm:8000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Could you please check php-fpm container? As I remember, the php-fpm default port is 9000, not 8000. Change port mapping from inside container from 8000 to 9000
ports: - "8000:9000"
Or if it already to use on your host you can expose the port only between containers.
expose: - "9000"