【发布时间】:2020-05-06 16:01:47
【问题描述】:
我正在构建一个 Rails 应用程序,我正在设置应用程序以部署在 docker 上,使用 Nginx 作为网络服务器。但是,我在使用 Docker 为应用程序设置 Nginx 时遇到问题。
我在运行docker-compose up 时不断收到此错误:
nginx:在 /etc/nginx/conf.d/mailing_list.conf 的上游“app:3000”中找不到 [emerg] 主机
这是我的docker-compose.yml 文件:
version: '3'
services:
app:
build:
context: .
dockerfile: ./docker/${RAILS_ENV}/Dockerfile
depends_on:
- database
ports:
- "3000:3000"
restart: always
volumes:
- .:/app
- gem-cache:/usr/local/bundle/gems
- node-modules:/app/node_modules
env_file:
- .env
environment:
RAILS_ENV: ${RAILS_ENV}
RACK_ENV: ${RACK_ENV}
database:
image: postgres:12.1
expose:
- "5432"
restart: always
env_file:
- .env
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
POSTGRES_HOST_AUTH_METHOD: ${DATABASE_HOST}
volumes:
- postgres-data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
nginx:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
depends_on:
- app
ports:
- "8080:8080"
restart: always
volumes:
- .:/app
- nginx-config:/etc/nginx
- nginx-log:/var/log/nginx
volumes:
gem-cache:
nginx-config:
nginx-log:
node-modules:
postgres-data:
这是我的nginx.conf 文件:
upstream app {
server app:3000;
}
server {
listen 8080;
listen [::]:8080;
root app/public;
index index.html index.htm;
server_name localhost;
location /app {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://app;
}
}
我尝试了很多解决方案,但似乎都没有。
我在运行docker-compose up 时不断收到此错误:
nginx:在 /etc/nginx/conf.d/mailing_list.conf 的上游“app:3000”中找不到 [emerg] 主机
我们将不胜感激任何形式的帮助。谢谢。
【问题讨论】:
-
即使使用
depends_on,在app未响应请求时也可能存在一些延迟。我认为this 是一个很好的解决方法。 -
谢谢@hmm,让我现在检查一下。
标签: ruby-on-rails docker nginx