Rails 求一个完整部署 nginx 、thin、postgreSQL 的指南<已解决,windows 部署确实有些麻烦>

roam · 2013年01月17日 · 最后由 roam 回复于 2013年01月19日 · 6058 次阅读

最近 webrick 常常出一些莫名问题,想把环境换成 nginx+thin,但是部署的时候总是不成功,thin 是能够正确运行的,但是加上 nginx 就不行了,想请大大们介绍介绍 nginx 对于 rails 的详细配置,谢谢啦 ~~~

ps: 我是在 windows 上开发的~~

用 passenger 把

nginx+passenger 比较稳定些。我试过 thin,在 freebsd 环境里,长期运行,还是会出现进程死的现象

#1 楼 @hisea
#2 楼 @ma95221 那么 passenger 和 nginx 又应该如何配置呢?我用 nginx 的时候,只能跑到根目录,在进去其他 action 就出现 404 页面了

passenger-install-nginx-module

根据我们的安装路径,nginx 的配置文件在/opt/nginx/conf/nginx.conf 操作: #ee /opt/nginx/conf/nginx.conf 找到并修改如下配置,注释 location:

server { listen 8088; #设置端口 server_name localhost;

root /usr/home/mayf/webdbjk/public;#rails app 路径 passenger_enabled on;

rails_env production; }

#location /{ #root html; #index index.html index.html; # } 说明: listen:监听的端口 server_name : 服务名,默认为 127.0.0.1 root: rails 程序存放的目录。记住一定要指到 public 目录 passenger_enabled: 是否开启 passenger。该选项一定要选择 on。 rails_env:发布模式

#5 楼 @ma95221 非常感谢,我是这样配置的,请问 thin 或者 rails 里面还要做其他配置么? 启动的时候,只要 start nginx 是不是呢?

启动 nginx # killall nginx # /opt/nginx/sbin/nginx 添加开机启动项只需在/etc/rc.local 中添加/opt/nginx/sbin/nginx 就行了。

文件读写授权,否则不能生成日志文件和导出文本文件 #chmod 777 log #cd public #chmod 777 *

另外在 config\production.rb 里面改动如下代码: #为 true 时,显示布局有问题 config.cache_classes = false

Disable Rails's static asset server

# In production, Apache or nginx will already do this #为 false 时,无法显示图片和 js 等 config.serve_static_assets = true

#8 楼 @ma95221 非常感谢,我试试~~~

#10 楼 @hisea thank you very much

#10 楼 @hisea #8 楼 @ma95221 我想再问一个问题,为什么我使用<%= form_tag :remote=>true ,method=>"post"%>的时候,有时候不刷新,但是有时候却全部刷新了,请问,这个是哪儿的原因呢?

不刷新是正常,刷新的时候可以看看 log 里面显示什么贴出来看看

#13 楼 @hisea Started POST "/checkmen/update_person_edit" for 127.0.0.1 at 2013-01-18 10:51:31 +0800 Processing by CheckmenController#update_person_edit as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"umzBmJtpGwieMVfzAitYLS4+shW36xYyFerl69ruHkY=", "component"=>"IS-PS-CA", "sapname"=>"", "firstname"=>"", "lastname"=>"", "eid"=>"", "email"=>"", "id"=>"810", "checkmanid"=>"9590", "commit"=>"save"} 然后是做了一些后来操作, ActionView::MissingTemplate (Missing template checkmen/update_person_edit, application/update_person_edit with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}.

#7 楼 @ma95221 777 权限是用户管理混乱的标志之一。

接收批评。有时候确实太偷懒了。

这个是提示:

ActionView::MissingTemplate (Missing template checkmen/update_person_edit, application/update_person_edit with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}.

缺少 template

#18 楼 @hisea 主要是 Form 包了 Form,所以里面的 form 的 remote=>true 不认了,我只是想 ajax 提交的,谢谢了。。。除了手写 submit 以外有没有什么方式能够让 remote 也 work 呢?谢谢了

20 楼 已删除
需要 登录 后方可回复, 如果你还没有账号请 注册新账号