3

我是 Rails 的新手,喜欢这种语言和开发环境。但是,在不使用 PostgreSQL 和/或 Heroku 的情况下,尝试将新应用程序推送到生产环境时,我感到非常沮丧。

出于工作相关的原因,我们使用带有 MySQL 作为数据库的机架空间云服务器。

我对设置乘客和 Nginx 感到沮丧。我已经按照 Ryan 的 Railscasts部署到 vps教程。

我可以在服务器上安装 ruby​​、mysql、passenger、Nginx、依赖项和 rails。但是当我尝试启动 Nginx 时,什么也没有发生。当我说什么都没有发生时,我的意思是我没有任何迹象表明它正在运行。我将浏览器指向该 IP 地址,并在浏览器中收到标准错误“此网页不可用”错误。我查看了错误日志,它是空白的。我还没有部署我的应用程序......只是想看看 Nginx 的默认屏幕。

有任何想法吗?我猜我在配置 Nginx 时缺少一个关键步骤,我只是不知道它是什么。

我的访问日志

.0.0.1 - - [14/Oct/2012:10:40:03 -0500] "GET / HTTP/1.1" 200 151 "-" "Wget/1.13.4 (linux-gnu)"
127.0.0.1 - - [14/Oct/2012:10:45:03 -0500] "GET / HTTP/1.1" 200 151 "-" "Wget/1.13.4 (linux-gnu)"
127.0.0.1 - - [14/Oct/2012:10:50:03 -0500] "GET / HTTP/1.1" 200 151 "-" "Wget/1.13.4 (linux-gnu)"
127.0.0.1 - - [14/Oct/2012:10:55:03 -0500] "GET / HTTP/1.1" 200 151 "-" "Wget/1.13.4 (linux-gnu)"
127.0.0.1 - - [14/Oct/2012:11:00:03 -0500] "GET / HTTP/1.1" 200 151 "-" "Wget/1.13.4 (linux-gnu)"

我的 Nginx.conf 文件

user deployer staff;
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.17;
    passenger_ruby /usr/local/bin/ruby;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

}
4

1 回答 1

5

从我的博客文章中,这几乎是关于这个确切设置http://blog.nikoroberts.com/post/45834702235/setting-up-a-rails-32-server-in-the-rackspace

你至少错过了 passenger_enabled on;

我的 nginx.conf

worker_processes  4;

events {
  worker_connections  1024;
}

http {
  passenger_root /home/deployer/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.17;
  passenger_ruby /home/deployer/.rvm/wrappers/ruby-1.9.3-p194/ruby;

  include       mime.types;
  default_type  application/octet-stream;

  sendfile        on;

  keepalive_timeout  65;

  client_max_body_size 5M;

  gzip  on;
  gzip_http_version 1.1;
  gzip_comp_level 1;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";
  gzip_proxied any;
  gzip_vary on;
  gzip_min_length 500;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  passenger_default_user deployer;
  #fast passenger respawn
  passenger_pool_idle_time 1000;

  server {
    listen 80;
    charset utf-8;
    server_name localhost;
    root /var/www/contactguru/current/public;
    passenger_enabled on;
    rails_env production;

    # fast passenger and rails respawn
    # from http://stackoverflow.com/a/2329221
    rails_spawn_method smart;
    rails_app_spawner_idle_time 0;
    rails_framework_spawner_idle_time 0;

    location ~ ^/(assets)/  {
      root /var/www/contactguru/current/public;
      gzip_static on;
      expires max;
      add_header Cache-Control public;
      # access_log /dev/null;
    }
  }
}
于 2012-10-15T18:12:07.107 回答