关于rails服务器配置以及操作
来源:互联网 发布:淘宝上100多的充气娃娃 编辑:程序博客网 时间:2024/06/08 06:51
连接远程服务器ssh命令:
ssh username@ip
然后就进入到相应权限的服务器内部终端。
接着就服务器中操作了,首先要配置服务器环境,安装ruby on rails参开rvm或者rbenv,尤其要注意细节。
http://ruby-china.org/wiki/install-rails-on-ubuntu-12-04-server
http://ruby-china.org/wiki/rbenv-guide
http://blog.csdn.net/yiyunhzy/article/details/10232395
剩下的工作就像在自己电脑里面操作一样运行web服务就OK啦。如果涉及到更高端的操作,均可参考资料。
重新编译assets:
RAILS_ENV=production bundle exec rake assets:precompile
关于服务器配置详情
步骤0 安装环境依赖
安装Xcode 4.1,Xcode4.2以及更高的版本在 Lion 仍然存在一些兼容性问题,强烈建议使用XCode 4.1,下载地址:
https://developer.apple.com/downloads/download.action?path=Developer_Tools/xcode_4.1_for_lion/xcode_4.1_for_lion.dmg
安装RVM
$ bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
配置RVM自动加载,将下面这一行代码添加到~/.bash_profile
中,然后退出iTerm并重新启动
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
安装 ruby-1.9.2-p290
$ rvm install 1.9.2
设置系统默认使用 ruby-1.9.2
$ rvm use 1.9.2 --default
步骤1 安装 Rails
安装Rails
$ gem install rails
Rails安装完成后,创建一个rails项目,假定你的项目叫做:awesome project
$ rails new awesome_project
启动Rails,并访问 http://localhost:3000
$ cd awesome_project$ rails server
步骤2 安装 Passenger 和 Nginx
首先通过gem安装passenger
$ gem install passenger
因为Nginx不支持动态module载入,所以需要通过Passenger来自动下载,编译,安装由Passenger修改版的Nginx:
安装Passenger + Nginx
$ passenger-install-nginx-module
Yes: download, compile and install Nginx for me. (recommended)
The easiest way to get started. A stock Nginx 1.0.10 with Passenger
support, but with no other additional third party modules, will be
installed for you to a directory of your choice.No: I want to customize my Nginx installation. (for advanced users)
Choose this if you want to compile Nginx with more third party modules
besides Passenger, or if you need to pass additional options to Nginx's
'configure' script. This installer will 1) ask you for the location of
the Nginx source code, 2) run the 'configure' script according to your
instructions, and 3) run 'make install'.
Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.
Enter your choice (1 or 2) or press Ctrl-C to abort: 这里建议选择1
Please specify a prefix directory [/opt/nginx]: /usr/local/nginx
当询问nginx的安装路径的时候,个人建议安装到/usr/local/nginx
下
当安装完成后,会在console中提示如何配置Nginx
Passenger会自动帮你将下面两行添加到Nginx的配置文件中/usr/local/nginx/conf/nginx.conf
(很人性化)
http { ... passenger_root /Users/Daniel/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.10; passenger_ruby /Users/Daniel/.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;}
请不要忘记将nginx
命令行程序连接到/usr/local/sbin
$ sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
步骤3 配置Nginx + Passenger + Rails
关于Nginx的配置,请参考Nginx的官方网站以及Passenger的官方网站
- http://wiki.nginx.org/Configuration
- http://www.modrails.com/documentation/Users%20guide%20Nginx.html
修改hosts
文件,给你的项目一个本地域名, 比如awesome_project.local
$ sudo vim /etc/hosts127.0.0.1 awesome_project.local
测试hosts
$ ping awesome_project.localPING awesome_project.local (127.0.0.1): 56 data bytes64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.054 ms
继续配置Nginx, 这里我给出一个最小可运行的Nginx配置文件
$ vim /usr/local/nginx/conf/nginx.conf
nginx.conf
worker_processes 1;events { worker_connections 1024;}http { passenger_root /Users/Daniel/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.10; passenger_ruby /Users/Daniel/.rvm/wrappers/ruby-1.9.2-p290/ruby; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name awesome_project.local; root /Users/Daniel/awesome_project/public; passenger_enabled on; rails_env development; }}
测试Nginx的配置文件语法是否正确
$ sudo nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动Nginx
$ sudo nginx
如何在修改Nginx的配置文件后,让Nginx载入新配置
$ sudo nginx -s reload
如何停止Nginx
$ sudo nginx -s stop
如何在不停Nginx的情况下,重新启动Passenger
$ cd path/to/your/awesome/project$ touch tmp/restart.txt
好了,这个时候你可以打开浏览器,访问你的awesome_project
网站了
http://awesome_project.local
注意:在配置文件里面给出的passenger_root是默认的,也是非常实用的,一般不需要改。自动生成的配置文件里,关于passenger_ruby部分也是默认,但是有可能和你的项目版本不同,有可能进行修改。通过我个人的经历,认为只要找到ruby的安装目录和执行程序,把它手动链接到/usr/bin/目录下面,以该ruby版本的具体版本名命令,这样就比较好了。
- 关于rails服务器配置以及操作
- Windows 服务器上的 Rails 配置策略
- ruby on rails 服务器的配置
- 关于james邮箱服务器配置、维护以及常见问题定位
- 关于Win2008系统DNS服务器安装配置操作教程
- Centos服务器配置操作
- Ruby on Rails学习笔记(1)--关于gem以及版本
- 关于android上传图片,视频,音频到rails后台服务器
- ruby on rails 环境搭建以及emacs开发环境配置
- ruby on rails爬坑(五):配置邮件服务器
- FTP服务器配置以及访问
- phpStorm配置服务器以及调试
- win7FTP服务器配置以及访问
- Eclipse服务器加载以及配置
- ubuntu12.10服务器关于网络配置、安装ssh、vsftpd以及编译安装LAMP等
- 关于nginx服务器的操作
- Hibernate的配置以及操作
- 关于kali开机自动启动ssh服务的方法以及配置kalissh的一些基本操作
- UVa 10026 - Shoemaker's Problem
- XDoInsist项目开发全程记录
- ADO.NET 中 SQL 语句的拼接
- UVa:1452 Jump
- POJ1035 Spell checker
- 关于rails服务器配置以及操作
- [LeetCodeSearch Insert Position
- exists和in的执行效率的区别
- Max Points on a Line
- ios学习笔记----实现一个带滑动手势的tabBarViewController,并可自定义tabBar
- 单例设计模式
- springmvc
- Oracle 学习之创建表空间,用户,权限
- 控制符号的可见性