Created
December 9, 2011 10:22
-
-
Save pobing/1451008 to your computer and use it in GitHub Desktop.
Deploying a Ruby on Rails application Nginx & Apache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
一 、Apache with passenger deploying rails project | |
1. 安装好 ror 环境 | |
bundle exec rake RAILS_ENV=production db:create | |
bundle exec rake RAILS_ENV=production db:migrate | |
2. 安装apache | |
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev | |
3.安装 passenger | |
sudo gem install passenger | |
sudo passenger-install-apache2-module | |
4. 按照提示 编辑 httpd.conf ,并添加如下配置 | |
sudo gedit /etc/apache2/httpd.conf | |
LoadModule passenger_module /home/dong/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9/ext/apache2/mod_passenger.so | |
PassengerRoot /home/d/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9 | |
PassengerRuby /home/d /.rvm/wrappers/ruby-1.9.2-p290/ruby | |
<VirtualHost *:80> | |
ServerName www.yourhost.com | |
DocumentRoot /somewhere/public # <-- be sure to point to 'public'! | |
<Directory /somewhere/public> | |
AllowOverride all # <-- relax Apache security settings | |
Options -MultiViews # <-- MultiViews must be turned off | |
</Directory> | |
</VirtualHost> | |
注释要去掉,才能重启成功 | |
5 .本机而不是服务器调试,记得修改host文件 添加domain | |
sudo gedit /etc/hosts | |
127.0.0.1 www.yourhost.com | |
6. sudo /etc/init.d/apache2 restart | |
brower url type: | |
http://www.yourhost.com | |
二 、nginx + passenger 部署rails | |
1. gem install passenger | |
passenger-install-nginx-module | |
第二个安装的是nginx,安装nginx的时候 可以用prefix=‘’指定安装的目录。 | |
装好后,进入nginx目录/sbin/nginx 启动nginx。打开浏览器 输入http://127.0.0.1 看到提示 说明安装成功 | |
2.配置 | |
在nginx/conf/nginx.conf 里修改 | |
http { | |
... | |
passenger_root /home/dong/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9; | |
passenger_ruby /home/dong/.rvm/wrappers/ruby-1.9.2-p290/ruby; | |
... | |
} | |
server { | |
listen 80; | |
server_name www.yourhost.com; | |
root /somewhere/public; # <--- be sure to point to 'public'! | |
passenger_enabled on; | |
#rails_env development; nginx的passenger模块默认是生产模式,如果是在本机进行开发 | |
} | |
3.重启 nginx。输入 http://local 可以访问app1 | |
4.写nginx脚本,启动和nginx的命令比较复杂,写个脚本来简化一下, | |
vi ~/.bashrc | |
alias sn='sudo /usr/local/nginx/sbin/nginx' | |
alias kn='sudo kill `cat /usr/local/nginx/logs/nginx.pid `' | |
alias rn='kn; sn' | |
5.更多nginx | |
nginx 中文维基: http://blog.chinaunix.net/link.php?url=http://wiki.codemongers.com%2FNginxChs | |
Ruby on Rails部署方案: http://www.cnblogs.com/ToDoToTry/archive/2011/07/27/2118805.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment