andreaskoch / dockerized-magento

A dockerized Magento Community Edition 1.9.x
BSD 3-Clause "New" or "Revised" License
278 stars 144 forks source link

502 Bad Gateway nginx/1.11.3 #23

Closed jujes closed 8 years ago

jujes commented 8 years ago

Hi, someone know how fix this issue? I'm deploying with jwilder/nginx-proxy https://github.com/jwilder/nginx-proxy

here my docker-compose.yml

thanks in advance! :)

installer:
  build: docker-images/installer
  environment:
    VIRTUAL_HOST: dockerized-magento.local,www.dockerized-magento.local
    HTTPS_METHOD: noredirect
    DOMAIN: dockerized-magento.local
    MAGENTO_ROOT: /var/www/html/web
    MYSQL_HOST: mysql
    MYSQL_DATABASE: magento
    MYSQL_USER: root
    MYSQL_PASSWORD: pw
    ADMIN_USERNAME: admin
    ADMIN_FIRSTNAME: Admin
    ADMIN_LASTNAME: Inistrator
    ADMIN_PASSWORD: password123
    ADMIN_FRONTNAME: admin
    ADMIN_EMAIL: admin@example.com
    ENCRYPTIONKEY: 731aea833710535779fe8c7c49bc6c4d
  volumes_from:
    - nginx
  links:
    - "cache:rediscache"
    - "sessions:redissession"
    - "fullpagecache:redisfullpagecache"
    - "solr:solr"
    - "mysql:mysql"
nginx:
  image: jwilder/nginx-proxy
  ports:
    - "80:80"
    - "443:443"
  links:
    - "php"
  volumes:
    - /home/vagrant/up/proxy/vhost.d:/etc/nginx/vhost.d:ro
    - /home/vagrant/up/proxy/certs:/etc/nginx/certs
    - /var/run/docker.sock:/tmp/docker.sock:ro
  volumes_from:
    - php
php:
  build: docker-images/php
  links:
    - "cache:rediscache"
    - "sessions:redissession"
    - "fullpagecache:redisfullpagecache"
    - "solr:solr"
    - "mysql:mysql"
  volumes:
    - .:/var/www/html
mysql:
  image: mysql:5.5
  ports:
    - "3306:3306"
  environment:
    MYSQL_ROOT_PASSWORD: pw
  volumes:
    - ./data/mysql:/var/lib/mysql
solr:
  build: docker-images/solr
cache:
  image: redis:latest
fullpagecache:
  image: redis:latest
sessions:
  image: redis:latest
andreaskoch commented 8 years ago

Hi @jujes, I have used the jwilder/nginx-proxy reverse proxy in the past and I believe using the reverse proxy in this project will help you much. You can run the jwilder/nginx-proxy outside of this project to run multiple sites on the port 80/443 with the same IP. Then you could change the port configuration of the nginx container to this:

nginx:
  image: nginx:latest
  ports:
    - "80"
    - "443"
  links:
    - "php"
  volumes:
    - /home/vagrant/up/proxy/vhost.d:/etc/nginx/vhost.d:ro
    - /home/vagrant/up/proxy/certs:/etc/nginx/certs
    - /var/run/docker.sock:/tmp/docker.sock:ro
  volumes_from:
    - php

... you no longer have to bind port 80 and 443. But I cannot give you a full example since I haven't used the jwilder/nginx-proxy in a while.

But I can highly recommend: Traefik All you have to do is add some labels to your web container and you are good to go:

version: '2'

services:
  caddy:
    image: abiosoft/caddy:latest
    volumes:
      - ./public:/srv
      - ./Caddyfile:/etc/Caddyfile
    labels:
      - "traefik.port=80"
      - "traefik.frontend.rule=Host:ak7.io,www.ak7.io"
      - "traefik.protocol=http"
      - "traefik.frontend.entryPoints=http,https"

or

version: '2'

services:
  web:
    image: nginx:1-alpine
    volumes:
      - ./config/nginx/conf.d:/etc/nginx/conf.d:ro
      - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    volumes_from:
      - phpfpm:ro
    networks:
      - front
      - back
    labels:
      - "traefik.port=80"
      - "traefik.frontend.rule=Host:wambo.co,www.wambo.co"
      - "traefik.protocol=http"
      - "traefik.frontend.entryPoints=http,https"
      - "traefik.frontend.passHostHeader=true"

  phpfpm:
    image: php:7-fpm-alpine
    volumes:
      - ./web:/var/www/html
    networks:
      - back

networks:
  front:
    driver: bridge
  back:
    driver: bridge