【问题标题】:Rails 3 - doesn't load pages (nginx doesn't start)Rails 3 - 不加载页面(nginx 不启动)
【发布时间】:2012-01-20 14:27:43
【问题描述】:

对于我的菜鸟问题,我很抱歉,但我真的不明白出了什么问题!

我想在 vds 上运行我的应用程序。所以,为此我使用下一个:

Ubuntu 10.04
PostgreSQL 9.1
Rails 3.1.3
Ruby 1.9.3p27
Nginx 1.0.11 (installed/compiled by passenger)
Phusion passenger 3.0.11
Capistrano

所以,我尝试使用由 Scaffold 创建的小型简单 Rails 应用程序进行配置。所以,这个应用程序工作正常(它使用 SQlite 并显示所有页面)。

然后我尝试启动使用 PostgreSQL 的应用程序。所以,我通过 capistrano 上传它,然后打印出来

$ cap deploy:start
* executing `deploy:start'

我也在我的服务器上打印

service nginx restart

所以,当我访问 ip 时,我只能获得旧应用程序的主要 rails 索引页面(如果我之前启动了非常简单的应用程序)或者它显示无法连接到服务器(否则),仅此而已。

我也试过了:

rails c production
> app.get("/")

然后我得到:

User Load (4.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
  CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
  User Load (0.0ms)  SELECT "users".* FROM "users" 
 => 500 

另外,当我尝试为我的应用启动或重新启动 nginx 时,它不想工作:

$ initctl list | grep nginx
nginx stop/waiting
$ service nginx start
nginx start/running, process 30746
$ initctl list | grep nginx
nginx stop/waiting

怎么了?

我的配置文件:

Nginx.conf:

user  root;

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/rvm/gems/ruby-1.9.3-head/gems/passenger-3.0.11;
    passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-head/ruby;

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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        # root and passenger i added.
        root /vol/www/apps/ror_tutorial/current/public                      #/current because of Capistrano
        passenger_enabled on;        

        #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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

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

}

config/deploy.rb

set :user, "root"                                                             
set :rails_env, "production"

default_run_options[:pty] = true                                              # Must be set for the password prompt from git to work
set :repository,  "git://github.com/Loremaster/sample_app.git"

set :application, "ror_tutorial"
set :deploy_to, "/vol/www/apps/#{application}"

set :scm, :git
set :branch, "master"

server "188.127.224.136", :app,
                          :web,
                          :db, :primary => true

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
   task :start do ; end
   task :stop do ; end
   task :restart, :roles => :app, :except => { :no_release => true } do
     run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
   end
end

【问题讨论】:

    标签: ubuntu ruby-on-rails-3.1 nginx passenger


    【解决方案1】:

    确保您在路由文件中设置了根路由,并从公共文件夹中删除 index.html,否则它将始终呈现在您的登录页面上。

    【讨论】:

    • 我的public 文件夹中没有索引文件。此外,路线是正确的。我的应用在我的本地机器和 heroku.com 上运行良好。
    【解决方案2】:

    我对nginx一无所知,只是提示一下:

    您是否正确设置了 PostgresSQL 服务器?

    【讨论】:

      【解决方案3】:

      我发现了问题所在 - 我忘记了 ';'在这个字符串中:

      Nginx.conf:

      root /vol/www/apps/ror_tutorial/current/public
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-17
        • 2018-02-08
        • 2017-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多