Docker nginx и приложение запущены, но приложение не отображается в браузере - PullRequest
0 голосов
/ 30 мая 2018

Я развернул приложение с помощью Docker + nginx + Puma, и оно кажется работающим, но приложение не открывается в браузере

моя конфигурация, как показано ниже

Dockerfile

FROM ruby:2.3.3

RUN apt-get update -qq && apt-get install -y build-essential libmysqlclient-dev mysql-client libmagickwand-dev imagemagick nodejs cron

# Define where our application will live inside the image
ENV RAILS_ROOT /home/ubuntu/myapp

# Create application home. App server will need the pids dir so just create everything in one shot
RUN mkdir -p $RAILS_ROOT/tmp/pids

# Set our working directory inside the image
WORKDIR $RAILS_ROOT


# Use the Gemfiles as Docker cache markers. Always bundle before copying app src.
# (the src likely changed and we don't want to invalidate Docker's cache too early)
# http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker/
COPY Gemfile Gemfile

COPY Gemfile.lock Gemfile.lock

# Prevent bundler warnings; ensure that the bundler version executed is >= that which created Gemfile.lock
RUN gem install bundler

# Finish establishing our Ruby enviornment
RUN bundle install

COPY config/puma.rb config/puma.rb

# Copy the Rails application into place
COPY . .
RUN bundle exec rake assets:precompile

RUN bundle exec whenever -i
EXPOSE 3000



# Define the script we want run once the container boots
# Use the "exec" form of CMD so our script shuts down gracefully on SIGTERM (i.e. `docker stop`)
#CMD [ "config/containers/app_cmd.sh" ]

CMD bundle exec puma -e production

Dockerfile-nginx

FROM nginx

RUN apt-get update -qq && apt-get -y install apache2-utils wget


ENV RAILS_ROOT /home/ubuntu/myapp
WORKDIR $RAILS_ROOT

RUN mkdir log

COPY public public/

COPY config/nginx.conf /etc/docker_example.nginx

RUN envsubst '$RAILS_ROOT' < /etc/docker_example.nginx > /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx","-g","daemon off;"]

docker-compose.yml

version: '2'
services:
  app:
    build: .
    command: bundle exec puma -e production
    env_file:
      - /home/ubuntu/myapp/.env
    expose:
      - "3000"
  web:
    build:
      context: .
      dockerfile: Dockerfile-nginx
    links:
      - app
    ports:
      - "80:80"

  sidekiq:
    build: .
    command: bundle exec sidekiq -e production -C config/sidekiq.yml
    env_file:
      - /home/ubuntu/myapp/.env

enter image description here

Кажется, все работает, но приложение не открывается в браузере.

Любая помощь будет высоко оценена.Заранее благодарны

Редактировать

nginx.conf

upstream puma_rails {
  server app:3000;
}

server {
  listen 80;
  client_max_body_size 4G;
  keepalive_timeout 10;

  error_page 500 502 504 /500.html;
  error_page 503 @503;

  server_name localhost puma_rails;
  root /home/ubuntu/myapp/public;
  try_files $uri/index.html $uri @puma_rails;

  location @puma_rails {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma_rails;
    # limit_req zone=one;
    access_log /home/ubuntu/myapp/log/nginx.access.log;
    error_log /home/ubuntu/myapp/log/nginx.error.log;
  }

  location = /50x.html {
    root html;
  }

  location = /404.html {
    root html;
  }

  location @503 {
    error_page 405 = /system/maintenance.html;
    if (-f $document_root/system/maintenance.html) {
      rewrite ^(.*)$ /system/maintenance.html break;
    }
    rewrite ^(.*)$ /503.html break;
  }

  if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
    return 405;
  }

  if (-f $document_root/system/maintenance.html) {
    return 503;
  }

  location ~ \.(php|html)$ {
    return 405;
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...