NGINX 502: Bad Gateway in Docker compose setup when editing Symfony 4 Controllers

  bad-gateway, docker, nginx, routes, symfony

After having this problem for a really long time having tried various approaches to fix this I want to ask it here. We have a docker compose setup and it work in Windows, Mac and also Linux except for this issue.

The docker-compose setup is basically very simple:

version: '3.5'
    container_name: nginx
    restart: always
      context: .
      dockerfile: _docker/nginx/Dockerfile

    container_name: php-fpm
      context: .
      dockerfile: _docker/php-fpm/Dockerfile
      target: base
    working_dir: /var/www

    container_name: redis
    image: redis:alpine

Whatever I do works fine except when I edit a Controller in Symfony (currently used version of Symfony is Symfony 4). After editing a Controller (e.g. adding a var_dump, but also when changing the Controller logic otherwis pushing F5 in the browser leads to a 502: Bad Gateway error. I have to restart nginx and php-fpm, sometimes twice. Then everything works and I can go on. My system is Linux Mint. It should not be a permission problem because the problem continues to exist even with 777 on the project files.

This is what the NGINX log file says:

2021/03/04 11:24:12 [error] 7#7: *116 recv() failed (104: Connection reset by peer) while reading response header from upstream, client:, server: _, request: "POST /admin-bulk-editing/article/?articlesPerPage=50 HTTP/1.1", upstream: "fastcgi://", host: "localhost:13443", referrer: "https://localhost:13443/admin-bulk-editing/article/?articlesPerPage=50"
2021/03/04 11:24:17 [notice] 1#1: signal 15 (SIGTERM) received, exiting
2021/03/04 11:24:17 [notice] 7#7: exiting
2021/03/04 11:24:17 [notice] 7#7: exit
2021/03/04 11:24:17 [notice] 1#1: signal 14 (SIGALRM) received
2021/03/04 11:24:17 [notice] 1#1: signal 17 (SIGCHLD) received from 7
2021/03/04 11:24:17 [notice] 1#1: worker process 7 exited with code 0
2021/03/04 11:24:17 [notice] 1#1: exit

What I have already tried is Nginx overwrites general symfony errors with 502 Bad Gateway but without any effect. Has anybody expierienced a similar issue and knows how to solve it? I am not that much into DevOps any help would be greatly appreciated.

Source: Docker Questions