工作中的测试项目因为无法正常使用 passenger+nginx、特此记录下解决流程、以便同仁借鉴 1、安装 Passenger
gem install passenger
默认安装最新版
2、安装 Nginx 到目录
/root/.rvm/gems/ruby-1.9.3-p547/gems/passenger-4.0.45/bin
使用命令
./passenger-install-nginx-module
选择安装路径为 /opt/nginx
按照流程提示、选择 ruby 即可
它会自动配置相关路径
如:passenger_root /root/.rvm/gems/ruby-1.9.3-p547/gems/passenger-4.0.45;
如:passenger_ruby /root/.rvm/gems/ruby-1.9.3-p547/wrappers/ruby;
3、配置 Nginx 命令文件
/etc/rc.d/init.d/nginx
#!/bin/sh
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ "$NETWORKING" = "no" ] && exit 0
nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
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 $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
4、配置项目文件
/opt/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /root/.rvm/gems/ruby-1.9.3-p547/gems/passenger-4.0.45;
passenger_ruby /root/.rvm/gems/ruby-1.9.3-p547/wrappers/ruby;
passenger_max_pool_size 12;
passenger_pool_idle_time 120;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name huodong.gcjtest.com; #网址
root /opt/projects/gcj_activities/public; #项目路径
passenger_enabled on;
client_max_body_size 200M;
location /uploads{
alias /opt/uploads;
}
}
}
5、给“/root”增加权限
sudo chmod o+x "/root" #由于RVM新版的安装路径由/usr/local/rvm 变为 /root/.rvm
6、启动 Nginx
/etc/init.d/nginx start