【问题标题】:Using a dedicated proxy container in front of Rails app container在 Rails 应用容器前使用专用代理容器
【发布时间】:2017-01-31 20:59:45
【问题描述】:

在将其部署到生产环境之前,我正在 dockerizing 一个 Rails 应用程序。

我能够创建一个 2 容器 (db+app) 系统,现在我正在尝试添加一个代理容器(使用 Nginx)在应用程序前面运行以提供静态资产。

我已经创建了一个从nginx:1.11-alpine 开始的基本容器,配置如下

server {
  listen *:80;
  location / {
    proxy_pass http://app:3000;
  }
} 

我现在可以将浏览器指向 http://0.0.0.0 并获取根页面,但是(显然)没有提供静态资源,我不知道如何继续。

我应该将静态资源从应用容器复制到代理容器吗?

我应该如何更新 Nginx 配置文件?

我的 docker-compose.yml 看起来像

version: '2'

volumes:
  postgres-data:
    driver: local

services:
...
  app:
    build: .
    command: bin/rails server -b 0.0.0.0
    ports:
      - 3000:3000
    links:
      - postgres:db
    depends_on:
      - postgres
  proxy:
    image: nginx:1.11-alpine
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
    command: nginx -g 'daemon off;'
    ports:
      - 80:80
      - 443:443
    links:
      - app
    depends_on:
      - app

谢谢。

【问题讨论】:

    标签: ruby-on-rails nginx docker docker-compose


    【解决方案1】:

    一种选择可能是通过共享卷挂载将应用容器中的assets 目录共享到 nginx 容器,并配置 nginx 以提供这些文件。

    【讨论】:

      猜你喜欢
      • 2018-03-08
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 2018-01-14
      • 1970-01-01
      相关资源
      最近更新 更多