CentOS6.5 use Nginx + Passenger to deploy the Ruby on Rails Environment
This article describes how to use Nginx + Passenger to deploy the Ruby on Rails environment. The operating system version used in this article is CentOS6.5.
1. Install ruby
Wget http://cache.ruby-lang.org/pub/ruby/ruby-2.0.0-p594.tar.gz
Mkdir-p/data/app_platform/ruby
Tar-zxvf ruby-2.0.0-p594.tar.gz
Cd ruby-2.0.0-p594
./Configure -- prefix =/data/app_platform/ruby
Make
Make install
Ln-sf/data/app_platform/ruby/bin/*/usr/bin/
Gem install rails
2. Install Nginx and Passenger
Passphrase can be installed in two ways. One is standalone, that is, passphrase runs independently, and then forwards ruby-related requests to passphrase through Nginx, and the other is integrated with Nginx for installation, easy to maintain. The first method is used here.
Passenger 4.0 or above can be integrated with Nginx 1.4 or above
Wget http://s3.amazonaws.com/phusion-passenger/releases/passenger-4.0.57.tar.gz
Wget http://nginx.org/download/nginx-1.4.4.tar.gz
Useradd-r www-s/sbin/nologin
Mkdir-p/data/app_platform/{nginx, passenger}
Tar-zxvf passenger-4.0.57.tar.gz
Mv-f passenger-4.0.57/*/data/app_platform/pasform
Tar-zxvf nginx-1.4.4.tar.gz
Cd nginx-1.4.4
. /Configure -- user = www -- group = www -- prefix =/data/app_platform/nginx -- with-http_stub_status_module -- with-http_ssl_module -- with-pcre -- with-http_perl_module -- with-http_realip_module -- with-http_addition_module -- add-module =/data /app_platform/passenger/ext/nginx
Make
Make install
Mkdir-p/data/app_platform/nginx/conf. d/
3. Configure Nginx
Add the Nginx Startup file/etc/init. d/nginx
#! /Bin/sh
#
# Nginx-this script starts and stops the nginx daemon
#
# Chkconfig:-85 15
# Description: Nginx is an HTTP (S) server, HTTP (S) reverse \
# Proxy and IMAP/POP3 proxy server
# Processname: nginx
# Config:/etc/nginx. conf
# Config:/etc/sysconfig/nginx
# Pidfile:/var/run/nginx. pid
# Source function library.
./Etc/rc. d/init. d/functions
# Source networking configuration.
./Etc/sysconfig/network
# Check that networking is up.
["$ NETWORKING" = "no"] & exit 0
Nginx = "/data/app_platform/nginx/sbin/nginx"
Prog = $ (basename $ nginx)
Sysconfig = "/etc/sysconfig/$ prog"
Lockfile = "/var/lock/subsys/nginx"
Pidfile = "/data/app_data/nginx/logs/nginx. pid"
NGINX_CONF_FILE = "/data/app_platform/nginx/conf/nginx. conf"
[-F $ sysconfig] & amp;. $ sysconfig
Start (){
[-X $ nginx] | exit 5
[-F $ NGINX_CONF_FILE] | exit 6
Echo-n $ "Starting $ prog :"
Daemon $ nginx-c $ NGINX_CONF_FILE
Retval =$?
Echo
[$ Retval-eq 0] & touch $ lockfile
Return $ retval
}
Stop (){
Echo-n $ "Stopping $ prog :"
Killproc-p $ pidfile $ prog
Retval =$?
Echo
[$ Retval-eq 0] & rm-f $ lockfile
Return $ retval
}
Restart (){
Configtest_q | return 6
Stop
Start
}
Reload (){
Configtest_q | return 6
Echo-n $ "Reloading $ prog :"
Killproc-p $ pidfile $ prog-HUP
Echo
}
Configtest (){
$ Nginx-t-c $ NGINX_CONF_FILE
}
Configtest_q (){
$ Nginx-t-q-c $ NGINX_CONF_FILE
}
Rh_status (){
Status $ prog
}
Rh_status_q (){
Rh_status>/dev/null 2> & 1
}
# Upgrade the binary with no downtime.
Upgrade (){
Local oldbin_pidfile = "$ {pidfile}. oldbin"
Configtest_q | return 6
Echo-n $ "Upgrading $ prog :"
Killproc-p $ pidfile $ prog-USR2
Retval =$?
Sleep 1
If [[-f $ {oldbin_pidfile} &-f $ {pidfile}]; then
Killproc-p $ oldbin_pidfile $ prog-QUIT
Success $ "$ prog online upgrade"
Echo
Return 0
Else
Failure $ "$ prog online upgrade"
Echo
Return 1
Fi
}
# Tell nginx to reopen logs
Reopen_logs (){
Configtest_q | return 6
Echo-n $ "Reopening $ prog logs :"
Killproc-p $ pidfile $ prog-USR1
Retval =$?
Echo
Return $ retval
}
Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart | configtest | reopen_logs)
$1
;;
Force-reload | upgrade)
Rh_status_q | exit 7
Upgrade
;;
Reload)
Rh_status_q | exit 7
$1
;;
Status | status_q)
Rh _ $1
;;
Condrestart | try-restart)
Rh_status_q | exit 7
Restart
;;
*)
Echo $ "Usage: $0 {start | stop | reload | configtest | status | force-reload | upgrade | restart | reopen_logs }"
Exit 2
Esac
Nginx main configuration file/data/app_platform/nginx/conf/nginx. conf
User www;
Worker_processes 4;
Error_log/data/app_data/nginx/logs/error. log error;
Pid/data/app_data/nginx/logs/nginx. pid;
Worker_rlimit_nofile 65535;
Events {
Use epoll;
Worker_connections 10240;
}
Http {
Passenger_root/data/app_platform/pasform;
Passenger_ruby/usr/bin/ruby;
Passenger_max_pool_size 10;
Passenger_debug_log_file/data/app_data/nginx/logs/passenger. log;
Passenger_show_version_in_header on;
Passenger_spawn_method smart;
Include 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 "';
Access_log logs/access. log main;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Server_tokens off;
Keepalive_timeout 60;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 1 128 k; #4 32 k
Client_max_body_size 8 m;
Client_body_buffer_size 128 k;
Fastcgi_connect_timeout 60;
Fastcgi_send_timeout 60;
Fastcgi_read_timeout 60;
Fastcgi_buffer_size 256 k;
Fastcgi_buffers 4 512 k; #8 128
Fastcgi_busy_buffers_size 512 k;
Fastcgi_temp_file_write_size 512 k;
# Fastcgi_intercept_errors on;
Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 1 64 k; #4 16
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
Include/data/app_platform/nginx/conf. d/*. conf;
Server {
Listen 80 default;
Server_name _;
Return 403;
}
}
The key part of the Nginx main configuration file is here, indicating that passpsenger is integrated into Nginx.
Passenger_root/data/app_platform/pasform;
Passenger_ruby/usr/bin/ruby;
Passenger_max_pool_size 10;
Passenger_debug_log_file/data/app_data/nginx/logs/passenger. log;
Passenger_show_version_in_header on;
Passenger_spawn_method smart;
Add VM
Server {
Server_name xxx.com.cn;
Access_log/data/app_data/nginx/logs/xxx. log main;
Root/data/zmkm_app/zmkm/public /;
Passenger_enabled on;
Index index.html index.htm;
Location/assets/LiveVideo.swf {
Root/data/zmkm_app/zmkm/public /;
Index index.html index.htm;
Passenger_enabled on;
}
}
Note that if Nginx needs to process ruby code under the directory specified by the VM, passenger_enabled on must be added. In this order, the content specified by location must be added again.
Build a Ruby on Rails environment on CentOS 5.9
Configure Ruby on Rails in CentOS and deploy Redmine
Build a Ruby On Rails platform using CentOS
Ruby on Rails and Laravel: getting started
Important article: Ruby-Linux/Windows installation, code development, and Rails practice
Ruby on rails:
Build Ruby On Rails in Ubuntu
Build Ruby on Rails on Ubuntu 13.10
Ruby on Rails 4 Tutorial Chinese Version HD complete PDF
This article permanently updates the link address: