Docker Community Forums

Share and learn in the Docker community.

502 bad gateway, nginx config looks good

I’m getting 502 bad gateway errors when NGINX config looks good. Can’t seem to figure out what is going wrong.

Here is docker-compose:

version: ‘3’
services:

#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: digital_ocean_app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
networks:
- app-network

#Nginx Service
webserver:
image: nginx
container_name: nginx-webserver
restart: unless-stopped
tty: true
extra_hosts:
- “my-laravel-social:127.0.0.1”
ports:
- “80:80”
- “443:443”
volumes:
- ./public:/var/www/public
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network

#MySQL Service
db:
image: mysql:5.7.22
container_name: mysql_db
restart: on-failure
tty: true
ports:
- “3306:3306”
environment:
MYSQL_DATABASE: my-laravel-social
MYSQL_ROOT_PASSWORD: trantystrobe
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network

#Docker Networks
networks:
app-network:
driver: bridge

#Volumes
volumes:
dbdata:
driver: local

Here is NGINX config:

server {
listen 80;
server_name my-laravel-social;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ .php$ {
try_files uri =404; fastcgi_split_path_info ^(.+\.php)(/.+);
fastcgi_pass mysql_db:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}

I’m aware of this, but I do not know why the error is happening

What does the logs say?
Also, where does port 9000 come from?

fastcgi_pass mysql_db:9000;