Nginx [SOLVED]: NGINX 502 bad gateway error in Docker for Windows and Symfony 4

Nginx [SOLVED]: NGINX 502 bad gateway error in Docker for Windows and Symfony 4

Home Forums Nginx Nginx [SOLVED]: NGINX 502 bad gateway error in Docker for Windows and Symfony 4

Tagged: , , , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36705

    Anonymous

    QuestionQuestion

    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;
        }
    }
    

    #36706

    Anonymous

    Accepted AnswerAnswer

    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"
    

    Source: https://stackoverflow.com/questions/47969769/nginx-502-bad-gateway-error-in-docker-for-windows-and-symfony-4
    Author: 0TshEL_n1ck
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.