From 442a68bb21f386d22f8ede44734f7ab2b2023487 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 13 Apr 2017 13:03:51 +0200 Subject: [PATCH] Put Nginx in front of Rails --- Dockerfile | 17 ++++++++++++++--- docker/nginx/asciinema.conf | 28 ++++++++++++++++++++++++++++ docker/supervisor/asciinema.conf | 11 +++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 docker/nginx/asciinema.conf create mode 100644 docker/supervisor/asciinema.conf diff --git a/Dockerfile b/Dockerfile index 033de97..f015967 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,6 @@ MAINTAINER Marcin Kulik # # Assuming you are running Docker Toolbox and VirtualBox: go to http://192.168.99.100:3000/ and enjoy. -EXPOSE 3000 - ARG DEBIAN_FRONTEND=noninteractive ARG NODE_VERSION=node_6.x ARG DISTRO=xenial @@ -37,11 +35,13 @@ RUN apt-get update && \ libtool \ libxml2-dev \ libxslt1-dev \ + nginx \ nodejs \ pkg-config \ ruby2.1 \ ruby2.1-dev \ sendmail \ + supervisor \ ttf-bitstream-vera # autoconf, libtool and pkg-config for libtsm @@ -102,6 +102,15 @@ RUN cd src && make RUN cd a2png && lein cljsbuild once main && lein cljsbuild once page +# configure Nginx + +COPY docker/nginx/asciinema.conf /etc/nginx/sites-available/default + +# configure Supervisor + +RUN mkdir -p /var/log/supervisor +COPY docker/supervisor/asciinema.conf /etc/supervisor/conf.d/asciinema.conf + VOLUME ["/app/config", "/app/log", "/app/uploads"] # 172.17.42.1 is the docker0 address @@ -113,6 +122,8 @@ ENV RAILS_ENV "development" # for ex. asciinema.example.com ENV HOST "localhost:3000" -CMD ["bundle", "exec", "rails", "server"] +CMD ["/usr/bin/supervisord"] # bundle exec rake db:setup # bundle exec sidekiq OR ruby start_sidekiq.rb (to start sidekiq with sendmail) + +EXPOSE 80 diff --git a/docker/nginx/asciinema.conf b/docker/nginx/asciinema.conf new file mode 100644 index 0000000..981aa6e --- /dev/null +++ b/docker/nginx/asciinema.conf @@ -0,0 +1,28 @@ +upstream rails-server { + server 127.0.0.1:3000 fail_timeout=0; +} + +server { + listen 80 default_server; + listen [::]:80 default_server; + + server_name _; + + root /app/public; + + client_max_body_size 16m; + + location / { + try_files $uri $uri/index.html $uri.html @rails; + } + + location @rails { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $http_host; + proxy_pass http://rails-server; + proxy_redirect off; + error_page 500 502 504 /500.html; # Rails error pages + } +} diff --git a/docker/supervisor/asciinema.conf b/docker/supervisor/asciinema.conf new file mode 100644 index 0000000..2dc2c30 --- /dev/null +++ b/docker/supervisor/asciinema.conf @@ -0,0 +1,11 @@ +[supervisord] +nodaemon=true + +[program:nginx] +command=/usr/sbin/nginx -g "daemon off;" +redirect_stderr=true + +[program:rails] +command=bundle exec rails server +redirect_stderr=true +directory=/app \ No newline at end of file