DockerとNginxの新機能です。これは愚かな質問かもしれませんが、Railsのファイルを見るためにnginxのボックスをどのように指すことができますか?基本的には、nginxボックスとアプリケーションボックスがあります。私はそれらがnginxボックスがそれらを読むことができるようにそれらのファイルを置くことができます知っていると思います。nginxのコンテナをdockerの静的ファイルに指し示す
version: "3"
services:
api:
build: "./api"
env_file:
- .env-dev
ports:
- "3000:3000"
depends_on:
- db
volumes:
- .:/app/api
command: rails server -b "0.0.0.0"
nginx:
build: ./nginx
env_file: .env-dev
volumes:
- .:/app/nginx
depends_on:
- api
links:
- api
ports:
- "80:80"
...
のAPI dockerfile:
FROM ruby:2.4.1-slim
RUN apt-get update && apt-get install -qq -y \
build-essential \
libmysqlclient-dev \
nodejs \
--fix-missing \
--no-install-recommends
ENV INSTALL_PATH /api
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY Gemfile $INSTALL_PATH
RUN bundle install
COPY . .
EXPOSE 3000
nginxのDockerfile:
FROM nginx
ENV INSTALL_PATH /nginx
RUN mkdir -p $INSTALL_PATH
COPY nginx.conf /etc/nginx/nginx.conf
# COPY ?
EXPOSE 80
nginxの設定ファイル(これは正しくコピーされている)今
daemon off;
worker_processes: 1;
events { worker_connections: 1024; }
http {
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;
# Rails Api
upstream api {
server http://api/;
}
# Configuration for the server
server {
# Running port
listen 80;
# Proxying the connections connections
location /api {
proxy_pass http://api;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /public/50x.html
error_page 404 /public/404.html
location = /50x.html {
root /api/public;
}
location = /404.html {
root /api/public
}
}
}
、私が行きますlocalhost:80
それはジェネリックを示しますc nginxフォルダ。しかし、私はどのようにレールapi/public /の公共のディレクトリをnginxのコンテナにリンクするのか不明です。
私はただCOPY path/to/rails/public path/nginx
できますか? nginxはそれらのファイルを見つけることをどこで期待していますか?
編集
私が正しい、私は/var/www/app_name
でそれらを置くべきであると考えていますか?
これを試してみます。それは多くの意味があります。 – user3162553
これを試してみましたが、上流の 'http:// api'のホストが無効になっています – user3162553
これは別の問題です。 'upstream'ブロック内のホストには、httpプレフィックスを付けるべきではありません。実際には、ロードバランスのために複数のホストを使用できる場合を除いて、 'upstream'ブロックを使用しません。 – MatTheWhale