Pointing nginx container to static files in docker -
i'm new docker , nginx , might stupid question how can point nginx box @ files in rails public? basically, have nginx box, , application box. know can put files nginx box can read them.
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 config (this correctly being copied over)
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 server server { # running port listen 80; # proxying 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 } } }
now, when go localhost:80
show generic nginx folder. however, i'm unsure how link public dir of rails api/public/ nginx container.
can copy path/to/rails/public path/nginx
. nginx expecting find files?
edit
i believe should putting them in /var/www/app_name
, correct?
the default location static content on nginx /etc/nginx/html
, put in var/www/app_name
long remember add
root /var/www/app_name
in corresponding location
block static content.
Comments
Post a Comment