4

I am trying to build a web application using docker-compose, with jwilder / nginx-proxy and letsencrypt companion, but when I try it, nginx throws me a 503 error.

"503 Service Temporarily Unavailable"

The docker-compose file that I have is as follows

version: '2'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy:alpine
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /etc/nginx/certs
      - /etc/nginx/vhost.d
      - /usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
    labels:
      - com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    restart: always
    environment:
      - NGINX_PROXY_CONTAINER=nginx-proxy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    volumes_from:
      - nginx-proxy:rw

  www:
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    expose:
      - "80"
    environment:
      - VIRTUAL_HOST=example.com, www.example.com
      - LETSENCRYPT_HOST=example.com, www.example.com
      - LETSENCRYPT_EMAIL=contact@example.com

My web app is builded with react, and i make this Dockerfile for build the container image:

FROM node:10-alpine as build

WORKDIR /usr/src/app

COPY package.json .

RUN npm install

COPY . .

RUN npm run build

FROM nginx:1.14-alpine

COPY --from=build /usr/src/app/build/ /usr/share/nginx/html

COPY www/nginx.config /etc/nginx/conf.d/default.conf

and this is the nginx.config used by this image:

server {
  server_name example.com www.example.com;
  listen 80 reuseport default;
  sendfile on;
  default_type application/octet-stream;
  gzip on;
  gzip_http_version 1.1;
  gzip_disable      "MSIE [1-6].";
  gzip_min_length   1100;
  gzip_vary         on;
  gzip_proxied      expired no-cache no-store private auth;
  gzip_types        text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  gzip_comp_level   9;
  root /usr/share/nginx/html;
  location / {
    try_files $uri $uri/ /index.html =404;
  }
}

The web app image is working fine, i can open it if i run only this. The problem is with the nginx-proxy and companion containers, maybe nginx-proxy is not able to find the www container?

Can someone helpe with this please.

kmilo93sd
  • 791
  • 1
  • 15
  • 35
  • How are you accessing your web app? Based on your compose file, you should access it using `example.com` as specified in your `VIRTUAL_HOST` variable. You should probably add another domain to this variable that points to your localhost - you can use anything.lvh.me – DannyB Aug 25 '19 at 08:04
  • im accessing to my web with localhost in my computer, and i try in my server with the domain , in both the error is the same. Im using the same setup for a nuxt project, the only difference is the nuxt project run with a node environment on port 3000, and this web use nginx to serve static files on port 80 – kmilo93sd Aug 25 '19 at 15:26

2 Answers2

1

You need to specify the correct VIRTUAL_HOST in the backends environment variable and make sure that they're on the same network (or docker bridge network)

Then it should automatically link to each other and be able to access via the domain you provided.

ZenithS
  • 987
  • 8
  • 20
0

The domain you provided as VIRTUAL_HOST="domain" could have expired. This is the reason my nginx-proxy was returning response "503 Service Temporarily Unavailable"