新人求助:
困扰了我好几天了,能试的方法都用遍了。
用 docker-compose 部署 Rails , 静态资源加载不了,浏览器显示 404
主要参考了这篇文章:
Docker for an Existing Rails Application
下面是可能涉及到的代码
另:英语很差,也硬着头皮在 stackoverflow 上也发贴求助,有人回复,但问题没有解决。
请求支招,多谢
1 app:
2 build: .
3
4 env_file: .env.production
5
6 environment:
7 RAILS_ENV: $RAILS_ENV
8
9 links:
10 - db
11
14 expose:
15 - "3000"
16
17 db:
18 image: postgres:9.4.5
19
20 volumes:
21 - myapp-postgres:/var/lib/postgresql/data
22
23 web:
24 build: .
25
26 dockerfile: config/containers/Dockerfile-nginx
27
28 volumes:
29 - ./public:/var/www/myapp/public
30
31 links:
32 - app
33 ports:
34 - "80:80"
2 FROM ruby:2.3.3-slim
12 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql-client libsqlite3-dev nodejs vim
15 ENV RAILS_ROOT /var/www/myapp
18 RUN mkdir -p $RAILS_ROOT/tmp/pids
19
21 WORKDIR $RAILS_ROOT
22
26 COPY Gemfile Gemfile
27
28 COPY Gemfile.lock Gemfile.lock
29
31 RUN gem install bundler
32
34 RUN bundle install
35
37 COPY . .
40 RUN bundle exec rake RAILS_ENV=$RAILS_ENV DATABASE_URL=postgresql://$POSTGRES_USER:[email protected]/$POSTGRES_PRODUCTION_DB assets:precompile
41 VOLUMES ["$RAILS_ROOT/public"]
46 CMD [ "config/containers/app_cmd.sh" ]
2 FROM nginx
12 RUN apt-get update -qq && apt-get -y install apache2-utils vim
15 ENV RAILS_ROOT /var/www/myapp
18 WORKDIR $RAILS_ROOT
21 RUN mkdir log
25 COPY public public/
28 COPY config/containers/nginx.conf /tmp/myapp.nginx
32 RUN envsubst '$RAILS_ROOT' < /tmp/myappv.nginx > /etc/nginx/conf.d/default.conf
35 CMD [ "nginx", "-g", "daemon off;" ]
# .env.production
RAILS_ENV=production
RAILS_ROOT=/var/www/myapp
SECRET_KEY_BASE=the_long_code
POSTGRES_PRODUCTION_DB=production_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=keep_secret_ps
在 docker-compose
的日志里还有这个 warn:
web_1 | 2017/03/02 05:45:14 [warn] 1#1: server name "/var/www/myapp/public" has suspicious symbols in /etc/nginx/conf.d/default.conf:16
web_1 | nginx: [warn] server name "/var/www/myapp/public" has suspicious symbols in /etc/nginx/conf.d/default.conf:16