简体   繁体   English

jwilder / nginx-proxy 503服务暂时不可用

[英]jwilder/nginx-proxy 503 Service Temporarily Unavailable

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. 我正在尝试使用docker-compose和jwilder / nginx-proxy和letencrypt伴侣来构建Web应用程序,但是当我尝试使用它时,nginx会抛出503错误。

"503 Service Temporarily Unavailable" “503服务暂时不可用”

The docker-compose file that I have is as follows 我拥有的docker-compose文件如下

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: 我的Web应用是用react构建的,我制作了这个Dockerfile来构建容器映像:

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: 这是此映像使用的nginx.config:

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. Web应用程序映像运行正常,如果仅运行此程序,则可以将其打开。 The problem is with the nginx-proxy and companion containers, maybe nginx-proxy is not able to find the www container? 问题出在nginx-proxy和伴侣容器上,也许nginx-proxy无法找到www容器?

Can someone helpe with this please. 有人可以帮忙吗?

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) 您需要在后端环境变量中指定正确的VIRTUAL_HOST ,并确保它们位于同一网络(或docker bridge网络)上

Then it should automatically link to each other and be able to access via the domain you provided. 然后,它应该自动相互链接,并能够通过您提供的域进行访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM