Linux system Configuration Nginx+ruby on Rails+mysql Super Raiders _ruby topics

Source: Internet
Author: User
Tags sleep create database ruby on rails

Install RVM

You typically use RVM or rbenv to install Ruby, where you choose RVM.

$ Curl-ssl Https://get.rvm.io | Bash-s Stable

Load into RVM:

$ SOURCE/HOME/LIBUCHAO/.RVM/SCRIPTS/RVM
$ rvm-v
RVM 1.25.12 (Stable) by Wayne E. Seguin <wayneeseguin@gmail. Com> ...

Then execute the following command:

$ type RVM
RVM is a function
...

Description RVM installed correctly.
Install Ruby

Installing Ruby with RVM

$ RVM Install 2.1.0
$ RVM Use 2.1.0--default
$ ruby-v
Ruby 2.1.0p0

Domestic server recommended to replace the RubyGems to Taobao Mirror

$ gem sources-r https://rubygems.org/
$ gem sources-a http://ruby.taobao.org/

Otherwise, installing a Gem can be very, very slow.
Installing Rails

In fact, Rails is also a Gem

$ gem Install rails--no-ri--no-rdoc-v ...
$ rails-v
Rails 4.0.2

The Rails environment is now installed.
Installing MySQL

Install Mysql and the corresponding library files:

$ sudo apt-get install mysql-server Libmysqlclient-dev

Then do some Setup settings:

$/usr/bin/mysql_secure_installation

Create the appropriate database and give it a new user with a small number of permissions:

mysql> CREATE DATABASE blix_production;
Mysql> GRANT all privileges on the blix_production.* to Blix@localhost identified by "123456";
mysql> flush Privileges;
Mysql> exit

Import data:

$ mysql-u blix-p Blix_production < Database.sql

Install Nginx

Nginx specifically handles static requests and acts as a reverse proxy for unicorn

Edit/etc/apt/sources.list, add the following two lines at the end

Deb http://nginx.org/packages/ubuntu/precise nginx
deb-src http://nginx.org/packages/ubuntu/precise nginx

Add Nginx Signature

$ wget http://nginx.org/keys/nginx_signing.key
$ sudo apt-key add Nginx_signing.key

Install Nginx

$ sudo apt-get update
$ sudo apt-get install Nginx

After the installation is complete, you can enter http://server-ipaddress in the browser to see if the installation is correct.
Configure Unicorn

First compile the static file:

$ rails_env=production Rake assets:clean
$ rails_env=production Rake assets:precompile

Unicorn Configuration Reference:

Worker_processes 2
timeout

app_path = File.expand_path (". /.. ", __file__)
working_directory app_path

listen 8080,: Tcp_nopush => true
Listen"/tmp/unicorn.sock " ,: Backlog =>

stderr_path App_path + "/log/unicorn.stderr.log" Stdout_path app_path
+ "/log/ Unicorn.stdout.log "

pid App_path +"/tmp/pids/unicorn.pid "

Unicorn from startup script:

#!/bin/sh SET-E # Example init script, this can is used with nginx, too, # since Nginx and unicorn accept the same signa
LS # Feel The following variables for your app:timeout=${timeout-60} App_root=/home/libuchao/blix App_user=libuchao pid= $APP _root/tmp/pids/unicorn.pid cmd= "unicorn_rails-d-e production-c $APP _root/config/ Unicorn.rb "action=" Set-u old_pid= "$PID. Oldbin" CD $APP _root | |  Exit 1 sig () {test-s "$PID" && kill-$1 ' cat $PID '} oldsig () {test-s $old _pid && kill-$1 ' Cat $old _pid '} case $action in Start) SIG 0 && Echo >&2 "already running" && exit 0 su
-C "$CMD"-$APP _user;
Stop) Sig QUIT && exit 0 echo >&2 "not running";;
Force-stop) Sig TERM && exit 0 echo >&2 "not running";; Restart|reload) SIG HUP && Echo Reloaded OK && exit 0 echo >&2 "couldn ' t reload, starting '
    $CMD ' instead 'Su-c "$CMD"-$APP _user; Upgrade) If Sig USR2 && sleep 2 && sig 0 && Oldsig QUIT then n= $TIMEOUT WH  Ile test-s $old _pid && test $n-ge 0 do printf '. ' && sleep 1 && n=$ ($n-1 ) done echo if test $n-lt 0 && test-s $old _pid then echo >&amp 2 "$old _pid still exists after $TIMEOUT seconds" Exit 1 fi exit 0 fi Echo >&2
"Couldn ' t upgrade, starting ' $CMD ' instead" su-c "$CMD"-$APP _user;;
Reopen-logs) sig USR1;;
*) echo >&2 "Usage: $ <start|stop|restart|upgrade|force-stop|reopen-logs>" Exit 1;;

 Esac

Make a soft connection to the shell under/etc/init.d/and make it boot from:

$ chmod +x/home/libuchao/blix/config/unicorn_init.sh
$ sudo ln-s/home/libuchao/blix/config/unicorn_init.sh/etc /init.d/unicorn
$ sudo update-rc.d unicorn defaults

Start Unicorn:

$ Service Unicorn Start

Enter the http://server_ipaddress:8080 view effect in the browser.
Configure Nginx

Nginx Configuration Reference:

Upstream Blix_backend {
  server unix:/tmp/unicorn.sock fail_timeout=0;
}

gzip on;
Gzip_disable "Msie6";
Client_max_body_size 150m;

server {
  listen default;
  return 403;
}

server {
  listen;
  server_name libuchao.com www.libuchao.com;

  Root/home/libuchao/blix/public;

  Try_files $uri/index.html $uri. html $uri @httpapp;

  Location @httpapp {
    proxy_redirect off   ;
    Proxy_set_header  Host $host;
    Proxy_set_header  x-forwarded-host $host;
    Proxy_set_header  x-forwarded-server $host;
    Proxy_set_header  x-real-ip    $remote _addr;
    Proxy_set_header  x-forwarded-for $proxy _add_x_forwarded_for;
    Proxy_buffering on  ;

    Proxy_pass http://blix_backend;
  }

  Location ~ ^ (/assets) {
    access_log off;
    Expires   Max;
  }


This should be done directly through the domain name.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.