Last active
March 12, 2018 13:18
-
-
Save nicolas-besnard/2fbc13037358226202d1 to your computer and use it in GitHub Desktop.
Nginx + Puma + Rails + Capistrano on Ubuntu 14.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
install_elasticsearch() { | |
echo " * -- Elasticsaerch -- *" | |
echo " * Update" | |
sudo apt-get -qq -y update | |
echo " * Install JDK" | |
sudo apt-get -qq -y install openjdk-7-jre-headless | |
echo " * Download deb (V1.4.2)" | |
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.2.deb >/dev/null 2>&1 | |
echo " * Install deb" | |
sudo dpkg -i elasticsearch-1.4.2.deb 2>&1 >/dev/null | |
echo " * Install Java Service Wrapper for Elasticsearch" | |
curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz | |
echo " * Create directory" | |
sudo mkdir /usr/local/share/elasticsearch | |
sudo mkdir /usr/local/share/elasticsearch/bin | |
echo " * Move directory " | |
sudo mv *servicewrapper*/service /usr/local/share/elasticsearch/bin/ | |
rm -Rf *servicewrapper* | |
sudo /usr/local/share/elasticsearch/bin/service/elasticsearch install | |
sudo ln -s `readlink -f /usr/local/share/elasticsearch/bin/service/elasticsearch` /usr/local/bin/rcelasticsearch | |
### Start ElasticSearch | |
echo " * Start Elasticsearch" | |
sudo service elasticsearch start | |
rm elasticsearch-1.4.2.deb | |
} | |
install_elasticsearch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream my_app { | |
server unix:///home/admin/owma-api/shared/tmp/sockets/owma-api.sock; | |
} | |
access_log /home/admin/owma-api/current/log/nginx.access.log; | |
error_log /home/admin/owma-api/current/log/nginx.error.log; | |
server { | |
listen 80; | |
server_name _ localhost; # need to listen to localhost for worker tier | |
location / { | |
proxy_pass http://my_app; # match the name of upstream directive which is defined above | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
location /assets { | |
alias /home/admin/owma-api/current/public/assets; | |
gzip_static on; | |
gzip on; | |
expires max; | |
add_header Cache-Control public; | |
} | |
location /public { | |
alias /home/admin/owma-api/current/public; | |
gzip_static on; | |
gzip on; | |
expires max; | |
add_header Cache-Control public; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 2; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
access_log /var/log/nginx/access.log; | |
sendfile on; | |
keepalive_timeout 65; | |
gzip on; | |
client_max_body_size 4M; | |
client_body_buffer_size 128k; | |
# Based on https://gist.github.com/plentz/6737338 | |
#server_tokens off; | |
#add_header Access-Control-Allow-Origin '*'; | |
#add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;"; | |
#add_header X-Frame-Options SAMEORIGIN; | |
#add_header X-Content-Type-Options nosniff; | |
include /etc/nginx/sites-enabled/*; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream project { | |
server unix:/home/cappie/apps/owma-api/shared/tmp/sockets/owma-api.sock; | |
} | |
server { | |
listen 80; | |
server_name dev-api.owma-project.com; | |
return 301 https://$host$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name dev-api.owma-project.com; | |
ssl_certificate /etc/letsencrypt/live/dev-api.owma-project.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/dev-api.owma-project.com/privkey.pem; | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; | |
root /home/cappie/apps/owma-api/current/public; | |
location / { | |
#if (!-f $request_filename) { | |
# proxy_pass http://project; | |
#} | |
proxy_pass http://project; # match the name of upstream directive which is defined above | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
#proxy_redirect off; | |
#proxy_set_header Host $host:$proxy_port; | |
#proxy_set_header X-Real-IP $remote_addr; | |
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
#client_max_body_size 10m; | |
#client_body_buffer_size 128k; | |
#proxy_connect_timeout 90; | |
#proxy_send_timeout 90; | |
#proxy_read_timeout 90; | |
#proxy_buffer_size 4k; | |
#proxy_buffers 4 32k; | |
#proxy_busy_buffers_size 64k; | |
#proxy_temp_file_write_size 64k; | |
} | |
location ^~ /.well-known/ { | |
allow all; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
install_mongodb () { | |
echo " * -- MongoDB -- *" | |
echo " * Add source" | |
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 2>&1 >/dev/null | |
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list 2>&1 >/dev/null | |
echo " * Update" | |
sudo apt-get -y update 2>&1 >/dev/null | |
echo " * Install" | |
sudo apt-get install -y mongodb-org 2>&1 >/dev/null | |
echo " * Launch MongoDB" | |
sudo service mongod start 2>&1 >/dev/null | |
cat /var/log/mongodb/mongod.log | grep "MongoDB starting" 2>&1 >/dev/null | |
if [ $? -e 0 ] | |
then | |
echo " * MongoDB installed !" | |
else | |
echo " * Mongo not installed :(" | |
fi | |
} | |
install_mongodb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
update_os () { | |
echo " * -- Update OS -- *" | |
echo " * Updating packages source" | |
sudo apt-get -qq -y update | |
echo " * Upgrade" | |
sudo apt-get -qq -y upgrade &> /dev/null | |
sudo apt-get -qq -y autoremove &> /dev/null | |
echo " * Install build-essential" | |
sudo apt-get -qq -y install build-essential libmagickcore-dev imagemagick libmagickwand-dev libxml2-dev libxslt1-dev &> /dev/null | |
echo " * Install custom" | |
sudo apt-get -qq -y install git-core curl nodejs htop emacs &> /dev/null | |
} | |
create_deploy_group() { | |
echo " * -- deploy group -- *" | |
cut -d: -f1 /etc/group | grep '^deploy' &> /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo " * Creating deploy group" | |
sudo groupadd deploy | |
echo " * Adding deploy group to sudoers file" | |
sudo bash -c "echo '%deploy ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers" | |
else | |
echo " * deploy group already exists" | |
fi | |
} | |
create_deploy_user () { | |
echo " * -- deploy user -- *" | |
id -u deploy &> /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo " * Creating user deploy" | |
sudo useradd -m -g deploy -s /bin/bash deploy | |
else | |
echo " * deploy user already exists" | |
fi | |
} | |
init_ssh_key () { | |
echo " * -- SSH KEY -- *" | |
echo " * Adding ssh key to authorized_keys" | |
test -d /home/deploy/.ssh &> /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo " * Creating .ssh directory" | |
sudo mkdir /home/deploy/.ssh | |
sudo chmod 700 /home/deploy/.ssh | |
sudo chown deploy /home/deploy/.ssh | |
sudo chgrp deploy /home/deploy/.ssh | |
fi | |
echo " * Fetch public key" | |
sudo curl -silent https://github.com/nicolas-besnard.keys > authorized_keys | |
sudo mv authorized_keys /home/deploy/.ssh/ | |
echo " * Changing chmod" | |
sudo chmod 600 /home/deploy/.ssh/authorized_keys | |
sudo chown deploy /home/deploy/.ssh/authorized_keys | |
sudo chgrp deploy /home/deploy/.ssh/authorized_keys | |
} | |
install_nginx () { | |
echo " * -- NGINX -- *" | |
nginx -v &> /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo " * Adding repository" | |
sudo add-apt-repository -y ppa:nginx/stable &> /dev/null | |
echo " * Updating packages source" | |
sudo apt-get -qq -y update &> /dev/null | |
echo " * Installing ..." | |
sudo apt-get -qq -y install nginx &> /dev/null | |
else | |
echo " * Nginx already installed" | |
fi | |
} | |
install_mysql () { | |
echo " * -- MySQL -- *" | |
echo " * Installing ..." | |
sudo apt-get -qq -y install mysql-server libmysqlclient-dev | |
sudo mysql_install_db | |
sudo mysql_secure_installation | |
} | |
install_postgre () { | |
echo " * -- PostgreSQL -- *" | |
echo " * Installing ..." | |
sudo apt-get -qq -y install postgresql libpq-dev postgresql-contrib-9.3 | |
sudo apt-get -qq -y install postgis postgresql-9.3-postgis-2.1 | |
} | |
install_rvm () { | |
echo " * -- RVM -- *" | |
echo " * Installing public key" | |
gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 &> /dev/null | |
echo " * Fetching file" | |
\curl -sSL https://get.rvm.io | sudo bash -s stable &> /dev/null | |
echo " * Reload source" | |
source /etc/profile.d/rvm.sh | |
sudo bash -c "echo 'source /etc/profile.d/rvm.sh' >> /etc/bash.bashrc" | |
echo " * Adding user go rvm group" | |
sudo usermod -a -G rvm deploy | |
} | |
update_os | |
create_deploy_group | |
create_deploy_user | |
init_ssh_key | |
install_nginx | |
install_mysql | |
install_rvm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment