网站用nginx在跑,网站经常疑似被挂掉,只因没钱买了个便宜的VPS,米国滴,经常被重启,为毛?米国也有G党?有木有?有木有?太坑爹了!

解决办法是把nginx添加到启动项中去,在 /etc/init.d/ 目录下添加 nginx 文件:
root@ubuntu: /etc/init.d/# vim nginx
#! /bin/sh
# chkconfig: - 58 74
# description: nginx is the Nginx daemon. 
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
#
# Author:  Ryan Norbauer
# Modified:     Geoffrey Grosenbach http://topfunky.com
# Modified:     David Krmpotic http://davidhq.com 
set -e 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf 
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME 
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0 
d_start() {
  $DAEMON -c $CONFIGFILE || echo -en "\n already running"
} 
d_stop() {
  kill -QUIT `cat $PIDFILE` || echo -en "\n not running"
} 
d_reload() {
  kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"
} 
case "$1" in
  start)
    echo -n "Starting $DESC: $NAME"
    d_start
        echo "."
  ;;
  stop)
    echo -n "Stopping $DESC: $NAME"
    d_stop
        echo "."
  ;;
  reload)
    echo -n "Reloading $DESC configuration..."
    d_reload
        echo "."
  ;;
  restart)
    echo -n "Restarting $DESC: $NAME"
    d_stop
    # One second might not be time enough for a daemon to stop,
    # if this happens, d_start will fail (and dpkg will break if
    # the package is being upgraded). Change the timeout if needed
    # be, or change d_stop to have start-stop-daemon use --retry.
    # Notice that using --retry slows down the shutdown process
    # somewhat.
    sleep 1
    d_start
    echo "."
  ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    exit 3
  ;;
esac 
exit 0

root@ubuntu: /etc/init.d/# chmod +x nginx
root@ubuntu: /etc/init.d/# update-rc.d nginx defaults

好像到这里就完事了...

查看一下
root@ubuntu: chkconfig --list
...
nginx                     0:off  1:off  2:on   3:on   4:on   5:on   6:off
...

相关链接:
https://github.com/lxneng/confs/blob/master/ubuntu/etc/init.d/nginx
https://github.com/lxneng/confs/raw/master/ubuntu/etc/init.d/nginx
http://hi.baidu.com/nivrrex/blog/item/afb98c54a6f7a1143a29353e.html

感谢国家,感谢罗小能

 
root@vps:/var/www/# rails c
/usr/local/lib/ruby/1.8/x86_64-linux/readline.so: libreadline.so.5: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/1.8/x86_64-linux/readline.so (LoadError)
    from /usr/local/lib/ruby/1.8/irb/completion.rb:10
    from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands/console.rb:3:in `require'
    from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands/console.rb:3
    from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands.rb:20:in `require'
    from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands.rb:20
    from script/rails:6:in `require'
    from script/rails:6

安装 libreadline-ruby1.8 即可解决此问题
root@vps:/var/www/# apt-get install libreadline-ruby1.8
 

VPS搭建ROR环境

2011.02.16
root@vps:~# apt-get install build-essential
root@vps:~# apt-get install git-core mercurial subversion
root@vps:~# vim /etc/mysql/my.cnf
    default-character-set=utf8
root@vps:/usr/local/src# apt-get install wget curl
root@vps:~# cd /usr/local/src/
root@vps:/usr/local/src# wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise_1.8.7-2011.03_amd64_ubuntu10.04.deb
更新地址:http://www.rubyenterpriseedition.com/download.html
root@vps:/usr/local/src# dpkg -i ruby-enterprise_1.8.7-2011.03_amd64_ubuntu10.04.deb
root@vps:~# apt-get install php5-cli php5-cgi libmysqld-dev libmysql-ruby libmysqlclient-dev  php5-mysql
root@vps:/usr/local/src# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
root@vps:/usr/local/src# tar zxvf pcre-8.10.tar.gz
root@vps:/usr/local/src# wget http://nginx.org/download/nginx-0.8.54.tar.gz
root@vps:/usr/local/src# tar zxvf nginx-0.8.54.tar.gz
root@vps:/usr/local/src/nginx-0.8.54# apt-get install libcurl4-openssl-dev
root@vps:/usr/local/src/nginx-0.8.54# ./configure --sbin-path=/usr/local/sbin     --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.10 --add-module=/usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/nginx/
root@vps:/usr/local/src/nginx-0.8.54# make
root@vps:/usr/local/src/nginx-0.8.54# make install
root@vps:/usr/local/src/nginx-0.8.54# service apache2 stop
root@vps:/usr/local/src/nginx-0.8.54# nginx
root@vps:/usr/local/src/nginx-0.8.54# vim /usr/local/nginx/conf/nginx.conf
    http {
        ...
        #--------------------passenger------------------------------------
        passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.2;
        passenger_ruby /usr/local/bin/ruby;
        #-----------------------------------------------------------------
    ...}
root@vps:/usr/local/src/nginx-0.8.54# mkdir /usr/local/nginx/conf/vhosts
root@vps:/usr/local/src/nginx-0.8.54# vim /usr/local/nginx/conf/nginx.conf
    http {
        ...
        include /usr/local/nginx/conf/vhosts/*;
    }
root@vps:/usr/local/src/nginx-0.8.54# vim /usr/local/nginx/conf/vhosts/rails_test
    server {
            listen       3000;
            server_name  100.110.110.110;
            root /var/www/test/railsdemo/public/;
            passenger_enabled on;
            rails_env development;
           }

root@vps:~# nginx -s reload

原文地址:http://w.lxneng.com/vps
 

Home Blog Delicious Github Flickr About Contact

© Miclle.Zheng . Powered by Forest Chalet