Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Last active August 29, 2015 13:57
Show Gist options
  • Save the-teacher/9563719 to your computer and use it in GitHub Desktop.
Save the-teacher/9563719 to your computer and use it in GitHub Desktop.
Digital ocean - Ubuntu Rails
ssh root@146.185.xxx.xxx
ssh rails@146.185.xxx.xxx
mkdir -p ~/.ssh
cat ~/.ssh/id_rsa.pub | ssh root@146.185.xxx.xxx 'cat >> ~/.ssh/authorized_keys'
cat ~/.ssh/id_rsa.pub | ssh rails@146.185.xxx.xxx 'cat >> ~/.ssh/authorized_keys'
User: rails
$ which nginx
/usr/sbin/nginx
$ which mysql
/usr/bin/mysql
$ which nodejs -v
/usr/bin/nodejs
$ nodejs -v
v0.6.19
$ which rvm
$ which psql
$ which convert
$ which searchd
$ which redis-server
@the-teacher
Copy link
Author

find / -name 'nginx'

/usr/share/nginx
/usr/share/doc/nginx
/usr/sbin/nginx
/etc/nginx
/etc/ufw/applications.d/nginx
/etc/init.d/nginx
/etc/default/nginx
/etc/logrotate.d/nginx
/var/lib/nginx
/var/lib/update-rc.d/nginx
/var/log/nginx

@the-teacher
Copy link
Author

cat /etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events { worker_connections 1024; }

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";
    gzip_types text/plain text/xml text/css text/comma-separated-values;
        upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

cat /etc/nginx/sites-enabled/default

server {
    listen   80;
    root /home/rails/public;
    server_name _;
    index index.htm index.html;

    location / {
        try_files $uri/index.html $uri.html $uri @app;
    }

#   location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi)$ {
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
            try_files $uri @app;
        }

     location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }

}

ps aux | grep unicorn

root       720  0.0  1.2  65728 13104 ?        Sl   Mar14   0:00 unicorn master -D -c /home/unicorn/unicorn.conf -E production

cat /home/unicorn/unicorn.conf

listen "127.0.0.1:8080"
worker_processes 2
user "rails"
working_directory "/home/rails"
pid "/home/unicorn/pids/unicorn.pid"
stderr_path "/home/unicorn/log/unicorn.log"
stdout_path "/home/unicorn/log/unicorn.log"

@the-teacher
Copy link
Author

for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done

@the-teacher
Copy link
Author

uname -a
Linux sitename.ru 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal

@the-teacher
Copy link
Author

apt-get remove nodejs

apt-get remove --purge package

apt-get clean

apt-get update
apt-get install -y python-software-properties python g++ make
add-apt-repository ppa:chris-lea/node.js
apt-get update
apt-get install nodejs

nodejs -v

v0.10.26

@the-teacher
Copy link
Author

apt-get install checkinstall

cd /tmp

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable

checkinstall

which redis-server
/usr/local/bin/redis-server

@the-teacher
Copy link
Author

wget http://sphinxsearch.com/files/sphinx-2.1.6-release.tar.gz
tar xvzf sphinx-2.1.6-release.tar.gz
cd sphinx-2.1.6-release

./configure

checkinstall

which searchd
/usr/local/bin/searchd

@the-teacher
Copy link
Author

apt-get install libjpeg-dev libpng-dev libtiff-dev libgif-dev

wget https://webp.googlecode.com/files/libwebp-0.4.0.tar.gz
tar xvzf libwebp-0.4.0.tar.gz
cd libwebp-0.4.0/

./configure
checkinstall

wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar xvzf ImageMagick.tar.gz
cd ImageMagick-6.8.8-8

./configure
checkinstall

which convert
/usr/local/bin/convert

@the-teacher
Copy link
Author

sudo vi /etc/hosts

146.185.xxx.xxx site.com

http://site.com

@the-teacher
Copy link
Author

ps aux | grep unicorn | grep master

root 720 0.0 1.1 65728 11976 ? Sl Mar14 0:00 unicorn master -D -c /home/unicorn/unicorn.conf -E production

kill 720

@the-teacher
Copy link
Author

/etc/init.d/nginx restart

@the-teacher
Copy link
Author

set BASH SHELL for user rails

chsh -s /bin/bash

echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment