Ruby 2.1.1 + Rails 4.1.1,使用 Capistrano 3.2.1 进行自动化部署。服务器是 Ubuntu Server 12.04 x64,采用 nginx + Passenger 的方案。配置过程如下:
$ curl -L get.rvm.io | bash -s stable $ source ~/.bashrc $ rvm install 2.1 $ rvm gemset create rails41 $ rvm use 2.1@rails41 $ gem install rails --verbose --no-ri --no-doc
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7 $ sudo aptitude install apt-transport-https ca-certificates
$ sudo vim /etc/apt/sources.list.d/passenger.list deb https://oss-binaries.phusionpassenger.com/apt/passenger precise main
$ sudo chown root: /etc/apt/sources.list.d/passenger.list $ sudo chmod 600 /etc/apt/sources.list.d/passenger.list $ sudo aptitude update; sudo aptitude upgrade -y $ sudo aptitude install nginx-extras passenger
$ sudo vim /etc/nginx/nginx.conf passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; passenger_ruby /home/haijia/.rvm/gems/ruby-2.1.2@rails41/wrappers/ruby;
$ sudo vim /etc/nginx/sites-enabled/www.haijia.org server { listen 80; server_name www.haijia.org; root /var/www/haijia/current/public; passenger_enabled on; passenger_friendly_error_pages on; }
$ sudo nginx -t $ sudo nginx
访问http://www.haijia.org/提示需要运行bundle install
。
$ cd /var/www/haijia/current/ $ bundle install
访问http://www.haijia.org/出现502 Bad Gateway
错误。
$ sudo vim /var/log/nginx/error.log 2014/07/13 00:22:50 [error] 3788#0: *35 upstream prematurely closed connection while reading response header from upstream, client: 123.12.12.123, server: www.haijia.org, request: "GET / HTTP/1.1", upstream: "passenger:/tmp/passenger.1.0.2988/generation-0/request:", host: "www.haijia.org"
$ ls -s /var/www/haijia/current/log/production.log 0 /var/www/haijia/current/log/production.log
折腾了 1 天,还是找不到出错的原因和解决方法。中间也用rvmsudo passenger-install-nginx-module
方法安装过 nginx 和 Passenger,但错误是一样的。
还望请各位前辈指点迷津!