|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
『特别提示:以下内容由金光新闻采集从互联网自动获取』
来源:http://www.kokkowon.com/archives/118
我的项目做了很久了,可惜没有rails环境支持,迟迟没有上线。最近买了hostmonster的虚拟主机,买它之前据说它是支持ror的,搞了大半天,全是扯淡…还得自己动手。
首先,你要去hostmonster申请SSH,去提交个Ticket就行了,很快的。
首先用ssh登陆服务器,为rails application创建一个工作区,
xx@xx.com [~]# mkdir rails
xx@xx.com [~]# cd rails
xx@xx.com [~]# rails inlocals
xx@xx.com [~]# cd inlocals
接下来,建立一个子域名供这个程序运行。登入cPanel,,点击 ’subdomains’,在第一个文本框中输入’inlocals’点击’Add’即可。
删除inlocals子域名创建的文件夹。将inlocals应用的public目录设为inlocals.xx.com的根根目录。
xx@xx.com [~]# rm -r ~/public_html/inlocals
xx@xx.com [~]# cd ~/public_html/
xx@xx.com [~]# ln -s ~/rails/inlocals/public inlocals
打开inlocals.xx.com可以看到我的Ruby on Rails的欢迎语。接下来将你的代码全部上传到rails/inlocals目录,把rails/inlocals/public /dispatch.cgi的权限设为755,在public目录下新建一个.htaccess文件,内容如下:
1. # General Apache options
2. AddHandler fcgid-script .fcgi
3. AddHandler cgi-script .cgi
4. Options +FollowSymLinks +ExecCGI
5.
6. # If you don't want Rails to look in certain directories,
7. # use the following rewrite rules so that Apache won't rewrite certain requests
8. #
9. # Example:
10. # RewriteCond %{REQUEST_URI} ^/notrails.*
11. # RewriteRule .* - [L]
12.
13. # Redirect all requests not available on the filesystem to Rails
14. # By default the cgi dispatcher is used which is very slow
15. #
16. # For better performance replace the dispatcher with the fastcgi one
17. #
18. # Example:
19. # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
20. RewriteEngine On
21.
22. # If your Rails application is accessed via an Alias directive,
23. # then you MUST also set the RewriteBase in this htaccess file.
24. #
25. # Example:
26. # Alias /myrailsapp /path/to/myrailsapp/public
27. # RewriteBase /myrailsapp
28.
29. RewriteBase /
30. RewriteRule ^$ index.html [QSA]
31. RewriteRule ^([^.]+)$ $1.html [QSA]
32. RewriteCond %{REQUEST_FILENAME} !-d
33. RewriteCond %{REQUEST_FILENAME} !-f
34. RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
35.
36. # In case Rails experiences terminal errors
37. # Instead of displaying this message you can supply a file here which will be rendered instead
38. #
39. # Example:
40. # ErrorDocument 500 /500.html
41.
42. ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
打开浏览器,输入http://inlocals.xx.com,over了。
我将我自己的域名www.inlocals.com绑定到inlocals.xx.com,就可以使用www.inlocals.com访问偶的网站了…
注:
忘了一个问题,我打开网站,发现图片和css、js文件显示不正常,由于我的css、js、图片文件都放在特定的目录下,加上RewriteCond %{REQUEST_FILENAME} !-d设置当目录存在时重写规则对该目录无效。这样图片和风格就可以正常显示了。
|
|