Various fixes that prevented production deployment
This commit is contained in:
parent
591845a25d
commit
459e86e25a
8 changed files with 134 additions and 279 deletions
|
|
@ -5,15 +5,12 @@ Prerequisites: A Debian Jessie server.
|
|||
Install PIP to get a recent version of Ansible:
|
||||
|
||||
apt install python-pip
|
||||
pip install ansible
|
||||
|
||||
Tun the Ansible playbook that comes with the debshots repository:
|
||||
Run the Ansible playbook that comes with the debshots repository:
|
||||
|
||||
cd ansible
|
||||
ansible-playbook debshost.yml
|
||||
|
||||
_(If you get "command not found" then run "hash -r" or "rehash" in your
|
||||
shell and try again.)_
|
||||
|
||||
ansible-playbook debshots.yml
|
||||
|
||||
# Installing debshots the manual way
|
||||
|
||||
|
|
@ -80,17 +77,23 @@ Clone the debshots Git repository.
|
|||
|
||||
## Migrate database
|
||||
|
||||
bundle exec rake db:migrate RAILS_ENV=production
|
||||
rails db:schema:load RAILS_ENV=production
|
||||
- rails db:migrate RAILS_ENV=production -
|
||||
|
||||
In config/database.yml: production: user/password/host must be commented out
|
||||
|
||||
## Fill/update the database with information from APT repositories
|
||||
|
||||
rails debshots:update_from_deb_repos RAILS_ENV=production
|
||||
rails debshots:update_longdescription_from_deb_repos RAILS_ENV=production
|
||||
|
||||
## Pre-render the static assets
|
||||
|
||||
bundle exec rake assets:precompile RAILS_ENV=production
|
||||
|
||||
rails assets:precompile RAILS_ENV=production
|
||||
|
||||
## Test the application:
|
||||
|
||||
bundle exec rails s -b 0.0.0.0 -e production
|
||||
rails s -b 127.0.0.1 -e production
|
||||
|
||||
Point your browser to http://...:3000/ and check the web site.
|
||||
|
||||
|
|
@ -117,155 +120,6 @@ Create a new user record:
|
|||
bundle exec debshots:update_longdescription_from_deb_repos
|
||||
|
||||
|
||||
|
||||
# Prepare production environment
|
||||
|
||||
## Install passenger to run the application behind nginx
|
||||
|
||||
Use the Ansible playbook to install Phusion Passenger - the component
|
||||
that makes the actual Ruby on Rails web application accessible from
|
||||
the Nginx web server.
|
||||
|
||||
## Example nginx vhost config
|
||||
|
||||
more_clear_headers 'X-Runtime';
|
||||
more_clear_headers 'X-Powered-By';
|
||||
more_clear_headers 'Server';
|
||||
server_tokens off;
|
||||
|
||||
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;
|
||||
|
||||
log_format proxy '[$time_local] Cache: $upstream_cache_status $upstream_addr $upstream_response_time $status $bytes_sent $remote_addr $request_uri "$http_referer" "$http_user_agent" $scheme';
|
||||
|
||||
# Performance
|
||||
passenger_max_pool_size 8;
|
||||
passenger_max_request_queue_size 200;
|
||||
|
||||
limit_req_zone $binary_remote_addr zone=one:20m rate=5r/s;
|
||||
|
||||
# Frontend caching and static asset delivery
|
||||
server {
|
||||
listen 85.25.83.22:80 default_server;
|
||||
listen 85.25.83.22:443 ssl;
|
||||
ssl_certificate /etc/letsencrypt/live/screenshots.debian.net/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/screenshots.debian.net/privkey.pem;
|
||||
|
||||
root /home/debshots/debshots/public;
|
||||
server_name _;
|
||||
access_log /var/log/nginx/cache-access.log proxy;
|
||||
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
# Tell the backend if the protocol used was HTTPS. Otherwise you get an infinite
|
||||
# redirection loop because the backend assumes that HTTP was spoken behind the
|
||||
# proxy.
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# Pass on the actual HTTP_HOST ("Host:" header) so that Rails can build proper absolute URLs
|
||||
proxy_set_header Host $host;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
gzip_proxied any;
|
||||
|
||||
location / {
|
||||
try_files /maintenance.html @backend;
|
||||
add_header X-Coffee front-main;
|
||||
}
|
||||
|
||||
location /json/ {
|
||||
try_files /maintenance.html @backend;
|
||||
proxy_cache my_cache;
|
||||
proxy_pass http://127.0.0.1:8888/;
|
||||
proxy_cache_lock on;
|
||||
proxy_cache_use_stale updating;
|
||||
add_header X-Coffee front-json;
|
||||
}
|
||||
|
||||
location /favicon.ico {
|
||||
alias /home/debshots/debshots/public/favicon.ico;
|
||||
}
|
||||
|
||||
location @backend {
|
||||
proxy_cache my_cache;
|
||||
proxy_pass http://127.0.0.1:8888;
|
||||
|
||||
# Avoid cache stampede - rather update once and deliver stale content
|
||||
proxy_cache_lock on;
|
||||
proxy_cache_use_stale updating;
|
||||
add_header X-Coffee front-rails;
|
||||
}
|
||||
|
||||
location /assets/ {
|
||||
alias /home/debshots/debshots/public/assets/;
|
||||
expires 1h;
|
||||
add_header X-Coffee front-assets;
|
||||
}
|
||||
location /logo/ {
|
||||
alias /home/debshots/debshots/public/logo/;
|
||||
expires 1h;
|
||||
add_header X-Coffee front-logo;
|
||||
}
|
||||
location /screenshots/ {
|
||||
alias /home/debshots/debshots/public/screenshots/;
|
||||
expires max;
|
||||
add_header X-Coffee front-screenshots;
|
||||
}
|
||||
location /images/ {
|
||||
alias /home/debshots/debshots/public/images/;
|
||||
expires 1h;
|
||||
add_header X-Coffee front-images;
|
||||
}
|
||||
}
|
||||
|
||||
# Backend rails application
|
||||
server {
|
||||
listen 127.0.0.1:8888;
|
||||
|
||||
root /home/debshots/debshots/public;
|
||||
|
||||
server_name _;
|
||||
access_log /var/log/nginx/rails-access.log;
|
||||
|
||||
passenger_enabled on;
|
||||
passenger_ruby /home/debshots/.rbenv/versions/2.3.1/bin/ruby;
|
||||
|
||||
|
||||
# Send thumbnails using X-Sendfile / X-Accel-Redirect
|
||||
# The correct thumbnail is computed by the Rails application so it cannot be served directly.
|
||||
location /thumbnail/ {
|
||||
expires 1h;
|
||||
proxy_cache_valid 404 15m;
|
||||
add_header X-Coffee back-thumbnail;
|
||||
limit_req zone=one burst=30;
|
||||
}
|
||||
|
||||
# Send public assets using X-Sendfile / X-Accel-Redirect (e.g. public/images/dummy/...)
|
||||
location /public/ {
|
||||
expires 1h;
|
||||
add_header X-Coffee back-public;
|
||||
|
||||
passenger_set_header X-Sendfile-Type X-Accel-Redirect;
|
||||
passenger_env_var HTTP_X_ACCEL_MAPPING /home/debshots/debshots/public/=/__send_file_accel/;
|
||||
passenger_pass_header X-Accel-Redirect;
|
||||
}
|
||||
|
||||
location /__send_file_accel/ {
|
||||
internal;
|
||||
alias /home/debshots/debshots/public/;
|
||||
add_header X-Coffee back-accel;
|
||||
expires 1d;
|
||||
more_clear_headers 'Set-Cookie';
|
||||
}
|
||||
|
||||
location /secretstatus {
|
||||
stub_status;
|
||||
access_log off;
|
||||
allow all;
|
||||
add_header X-Coffee back-status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Supported URL paths (aka routes)
|
||||
|
||||
_For up-to-date information please check config/routes._
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue