我对Docker和Nginx非常陌生,这可能是一个愚蠢的问题,但我怎么才能指出我的nginx框来查看Rails中的文件?基本上,我有一个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"
...
阿比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
}
}
}
现在,当我去它显示了基因组c nginx文件夹。但是,我不确定如何将rails api/public /的公共目录链接到nginx容器。
我可以只为COPY path/to/rails/public path/nginx
。 nginx希望能够找到这些文件?
编辑
我相信我应该把它们放在/var/www/app_name
,是否正确?
好吧,我会试试看。这很有道理。 – user3162553
好吧,试过了,现在我得到上游'http:// api'的无效主机 – user3162553
这是一个单独的问题。 “上游”块中的主机不应该有一个http前缀。事实上,除非您有多个可用于负载平衡的主机,否则我根本不会使用“上游”块。 – MatTheWhale