以前在Hostmonster上买了个空间,后来因速度不稳定一直没用。依稀记得hostmonster是支持rails的于是就试试看能不能部署个简单的应用上去,因为从来没部署过还是花了不少时间。
1、申请SSH
这个老早就申请了,似乎只要把自己的身份证照片发过去就可以了,很快
2、登录SSH然后新建app
位置随便放,比如我的:~/rails/myapp #myapp是我的app名字
cd ~/rails
rails -D myapp
我是新手,开始没加-D参数一直没法得到dispatch.fcgi,上网查了好久才知道要加-D...这个问题耽误了我很多时间
3、建子域名
在cPanel里点 subdomains新建子域名,输入自己的子域名,比如myapp
输完子域名后鼠标点下Document Root的输入框会自动给出root路径,默认就行。然后点create
4、SSH里删除~/public_html/myapp目录
rm -rf ~/public_html/myapp
5、链接快捷方式
ln -s ~/rails/myapp/public ~/public_html/myapp
6、.htaccess文件配置
如果是windows下没法新建这种格式的文件,先把public_html目录下的.htaccess下载到本地编辑了再上传
编辑好的.htaccess放到~/rails/myapp/public目录下(就是你的app的public目录下)
# General Apache options AddHandler fcgid-script .fcgi AddHandler cgi-script .cgi Options +FollowSymLinks +ExecCGI # If you don't want Rails to look in certain directories, # use the following rewrite rules so that Apache won't rewrite certain requests # # Example: # RewriteCond %{REQUEST_URI} ^/notrails.* # RewriteRule .* - [L] # Redirect all requests not available on the filesystem to Rails # By default the cgi dispatcher is used which is very slow # # For better performance replace the dispatcher with the fastcgi one # # Example: # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] RewriteEngine On # If your Rails application is accessed via an Alias directive, # then you MUST also set the RewriteBase in this htaccess file. # # Example: # Alias /myrailsapp /path/to/myrailsapp/public # RewriteBase /myrailsapp RewriteBase / RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] # In case Rails experiences terminal errors # Instead of displaying this message you can supply a file here which will be rendered instead # # Example: # ErrorDocument 500 /500.html ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
现在就可以正常使用了