openbridge / nginx

NGINX Accelerated! This is a Docker image that creates a high performance (FAST!), optimized image for NGINX for use with Redis and PHP-FMP. Deliver sites and applications with performance, reliability, security, and scale. This NGINX server offers advanced performance, web and mobile acceleration, security controls, application monitoring, and management.
https://www.openbridge.com/
MIT License
233 stars 53 forks source link

Container fails to start: unknown directive "max_fails=3" #32

Closed thilak-rao closed 5 years ago

thilak-rao commented 5 years ago

Describe the bug I am trying to use docker image openbridge/nginx:latest to run wordpress:php7.1-fpm-alpine on another container.

I created a volume called root and mapped it to /var/www/html on the wordpress container and mapped the same volume to /usr/share/nginx/html in nginx container.

My Dockerfile:

FROM openbridge/nginx:latest
ENV NGINX_CONFIG=php
ENV NGINX_DEV_INSTALL=true
ENV PHP_FPM_UPSTREAM=wordpress:9000
ENV NGINX_SERVER_NAME=localhost

The container fails to start with this error:

nginx: [emerg] unknown directive "max_fails=3" in /etc/nginx/upstream.d/proxy.conf:3

Maybe I'm just not following the docs correctly. Could you help me out?

thilak-rao commented 5 years ago

Setting these variables fixed my previous issue:

ENV PHP_FPM_UPSTREAM="wordpress:9000"
ENV NGINX_PROXY_UPSTREAM="wordpress:9000"
ENV REDIS_UPSTREAM="redis:6379

but now when I run curl https://localhost --insecure, I get this instead of wordpress:

    <html><head><meta http-equiv="refresh" content="1">
    </head><body><br/><br/><h1>HTTP 502 / No backend servers found at the moment</h1>
    <h3>Refreshing automatically to reconnect to backend...</h3></body>
tspicer commented 5 years ago

Normally a 502 error will occur because of different startup times between your instances. In this case, it is likely PHP and Wordpress were not available for Nginx to connect. It might take 20-30 seconds.

thilak-rao commented 5 years ago

That's unlikely. Here's the output of docker ps:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                      NAMES
509706a826b3        proxy_nginx         "/docker-entrypoint.…"   6 minutes ago       Up 6 minutes        0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   nginx
492bb39a3bc2        mysql:5.7           "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        3306/tcp, 33060/tcp                        mysql
c9e4aa077510        redis:alpine        "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        6379/tcp                                   redis
2d9ed52a0572        wordpress:php7.1-fpm-alpine      "docker-entrypoint.s…"   About an hour ago   Up About an hour    9000/tcp                                   wordpress

Thanks for taking the time to open source this image! It's a great starting point with good defaults. 🍻

tspicer commented 5 years ago

can you do docker logs for the wordpress container? Would be curious what it says. Also, can you share your docker compose yml?

thilak-rao commented 5 years ago

First Dockerfile:

FROM wordpress:php7.1-fpm-alpine
RUN mkdir -p /var/www/html/wp-content/themes/demo/
COPY . /var/www/html/wp-content/themes/demo/

First docker-compose.yml:

version: '3.7'

services:
  wordpress:
    build: .
    container_name: wordpress
    restart: unless-stopped
    volumes:
      - thilak_root:/var/www/html
    networks:
      - proxy
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_PASSWORD: 'super_secret'

networks:
  proxy:
    external: true

volumes:
  wordpress_root:
    external: true

Second Dockerfile:

FROM openbridge/nginx:latest
ENV NGINX_CONFIG=php
ENV NGINX_DEV_INSTALL=true
ENV PHP_FPM_UPSTREAM="wordpress:9000"
ENV NGINX_PROXY_UPSTREAM="wordpress:9000"
ENV REDIS_UPSTREAM="redis:6379"
ENV NGINX_SERVER_NAME=localhost

Second docker-compose.yml:

version: '3.7'

services:
  nginx:
    build: .
    restart: unless-stopped
    container_name: nginx
    ulimits:
      nproc: 65535
      nofile:
        soft: 49999
        hard: 99999
    tmpfs: /var/cache
    tty: true
    volumes:
      - type: volume
        source: wordpress_root
        target: /usr/share/nginx/html
        volume:
          nocopy: true
    logging:
      driver: "json-file"
      options:
        max-size: "1k"
        max-file: "3"
    networks:
      - proxy
    ports:
      - 80:80
      - 443:443

  mysql:
    image: mysql:5.7
    container_name: mysql
    restart: unless-stopped
    networks:
      - proxy
    environment:
      MYSQL_ROOT_PASSWORD: 'super_secret'
    volumes:
      - mysql:/var/lib/mysql

  redis:
    image: redis:alpine
    container_name: redis
    networks:
      - proxy
    restart: unless-stopped

networks:
  proxy:
    external: true

volumes:
  wordpress_root:
    external: true
  mysql:
    external: true

Output of docker logs of WordPress container

WordPress not found in /var/www/html - copying now...
WARNING: /var/www/html is not empty! (copying anyhow)
Complete! WordPress has been successfully copied to /var/www/html
[28-Jan-2019 18:27:59] NOTICE: fpm is running, pid 1
[28-Jan-2019 18:27:59] NOTICE: ready to handle connections
tspicer commented 5 years ago

I don't see your wordpress container in the compose file. I don't think it is going to understand wordpress:9000 as a reference if you are not doing this.

thilak-rao commented 5 years ago

Are you sure about that? My previous setup involved wordpress/php7.1-apache with nginx:latest on the front and I was able to proxy wordpress:80 just fine, and WordPress container was able to connect with MySQL.

My understanding was containers that share the same network (proxy in my case) can talk to one another.

thilak-rao commented 5 years ago

@tspicer To test your hypothesis, I moved wordpress:php7.1-fpm-alpine image into the docker compose file, but I still have the same issue

curl https://localhost --insecure

# Output: 
    <html><head><meta http-equiv="refresh" content="1">
    </head><body><br/><br/><h1>HTTP 502 / No backend servers found at the moment</h1>
    <h3>Refreshing automatically to reconnect to backend...</h3></body>

You can clone this repo and run start.sh (this shell script creates the external volumes).

thilak-rao commented 5 years ago

When I SSH into the docker openbridge/nginx:latest container, I'm able to ping wordpress hostname successfully.