Put Nginx in front of Rails

dockerfile-tweaks
Marcin Kulik 7 years ago
parent 0823c79b54
commit 442a68bb21

@ -16,8 +16,6 @@ MAINTAINER Marcin Kulik <support@asciinema.org>
#
# 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

@ -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
}
}

@ -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
Loading…
Cancel
Save