Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo Docker on Rails
FROM ubuntu:trusty
# Update the repository
RUN apt-get update
# Install necessary tools
RUN apt-get install -y wget net-tools build-essential git
# Setup Install Nginx
RUN wget -q -O - http://nginx.org/keys/nginx_signing.key | apt-key add -
RUN echo 'deb http://nginx.org/packages/ubuntu/ trusty nginx' | tee /etc/apt/sources.list.d/nginx.list
# Setup Install Ruby
RUN wget -q -O - http://apt.hellobits.com/hellobits.key | apt-key add -
RUN echo 'deb [arch=amd64] http://apt.hellobits.com/ trusty main' | tee /etc/apt/sources.list.d/hellobits.list
# Install Nginx and Ruby
RUN apt-get update
RUN apt-get install -y nginx ruby-2.1
# Install Bundler
RUN gem install bundler
# Copy Nginx files
ADD nginx.conf /etc/nginx/nginx.conf
ADD myapp.conf /etc/nginx/sites/myapp.conf
# set workdir
WORKDIR /home/ubuntu/my_app
ADD . /var/www/my_app/
# Ports
EXPOSE 80
# Execute
CMD ["/usr/sbin/nginx", "-c", "/etc/nginx/nginx.conf", "-g", "daemon off;"]
upstream my_app {
server unix://tmp/my_app.sock fail_timeout=0;
}
server {
listen 80;
client_max_body_size 2M;
server_name localhost;
keepalive_timeout 5;
root /var/www/my_app/public;
access_log off;
error_log off;
location ~ ^/(assets)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
try_files $uri/index.html $uri.html $uri @app;
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
error_page 403 /403.html;
}
location @app {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_pass http://my_app;
}
location = /favicon.ico {
expires max;
add_header Cache-Control public;
}
location ~ \.php$ {
deny all;
}
}
user www-data www-data;
worker_processes 2;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
accept_mutex on;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_requests 10;
keepalive_timeout 30;
tcp_nodelay off;
tcp_nopush on;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security max-age=31536000;
server_tokens off;
client_header_timeout 60;
client_body_timeout 60;
ignore_invalid_headers on;
send_timeout 60;
server_name_in_redirect off;
large_client_header_buffers 2 2k;
server_names_hash_max_size 4096;
types_hash_max_size 4096;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_min_length 500;
gzip_proxied any;
gzip_disable "MSIE [1-6] \.";
gzip_types text/plain text/css application/x-javascript text/xml
application/xml application/xml+rss text/javascript
image/svg+xml;
include /etc/nginx/sites/*;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment