我正在尝试使用带有jwilder / nginx-proxy和letencrypt伴侣的docker-compose构建Web应用程序,但是当我尝试使用它时,nginx会抛出503错误。
“ 503服务暂时不可用”
我拥有的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
我的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
这是此图像使用的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;
}
}
Web应用程序映像运行正常,如果仅运行此程序,则可以将其打开。问题出在nginx-proxy和伴随容器上,也许nginx-proxy无法找到www容器?
有人可以帮忙吗?
答案 0 :(得分:0)
您需要在后端环境变量中指定正确的VIRTUAL_HOST
,并确保它们位于同一网络(或docker bridge网络)上
然后它应该自动相互链接,并能够通过您提供的域进行访问。