rails 4 nginx和unicorn只提供公共文件(html)

时间:2013-09-09 20:57:30

标签: ruby-on-rails ruby ubuntu nginx unicorn

运行Ubuntu 12.10 x64,Nginx,Unicorn,Rails 4

bundle exec rake routes正确显示所有路由,但当我访问任何路由(控制器/操作)时,它超时(nginx 504)。当我打开任何静态HTML文件(公共目录)时,它工作正常。

尝试重启服务器,nginx,独角兽,安装了所有的宝石。我还缺少什么?

这是我的独角兽日志 http://pastebin.com/5BHzqCA9

1 个答案:

答案 0 :(得分:0)

您必须将套接字文件添加到 unicorn.rb 配置文件并将其设置为侦听器。像这样:

sock_file = "path/to/unicorn.sock"
......
listen sock_file

在您的nginx conf中,您需要:

upstream rails_server {
   server unix:/path/to/sock;
}
server {
 listen  80;
 server_name  example.com;
 root /path/to/public;
 access_log /path/to/log/nginx_access.log;
 error_page   500 502 503 504  /50x.html;
location = /50x.html {
     root   /path/to/public;
 }
try_files $uri, @rails;
 location @rails {
 proxy_pass http://rails_server;
 proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
 proxy_set_header Host $http_host;
 proxy_redirect off;
 }
}