新手问题 部署 Rails 访问 demo 实例,总是提示 ‘Incomplete response received from application’

cym2015 · 发布于 2017年3月20日 · 最后由 cym2015 回复于 2017年3月20日 · 390 次阅读
96

本人新手,第一次在linux上部署rails,由于周围没有老前辈指引,虽已尝试部署多日,但是总是不成。无奈,来社区发帖,希望前辈们指点一二,小弟万分感激。

部署上是参照社区wiki:https://ruby-china.org/wiki/rvm-guide 示例,在ubuntu上操作,除最后一步安装nginx是采用的自行下载源码,通过rvmsudo passenger-install-nginx-module外,其他均与示例中保持一致操作。

我本地的demo实例,rails s 启动后,是可以通过http://localhost:3000/say/hello,正常访问, 但是,通过sudo /opt/nginx/sbin/nginx 启动nginx后,本地访问http://localhost/say/helloIncomplete时,总是提示‘ response received from application’

以下是nginx的配置文件


#user  nobody;
user caiyuanmao caiyuanmao;
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 /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2;
    passenger_ruby /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/wrappers/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;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
    root   /home/caiyuanmao/demo/public;
    passenger_enabled on;

        #location / {
        #alias /websites/secondapp/public$1;  # <-- be sure to point to 'public'!
            #passenger_base_uri /subpath;
            #passenger_app_root /websites/secondapp;
            #passenger_document_root /websites/secondapp/public;
            #passenger_enabled on;
            #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 ssl;
    #    server_name  localhost;

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

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

nginx的error.log如下:

[ 2017-03-19 23:47:31.0842 25983/b6810700 age/Wat/WatchdogMain.cpp:1281 ]: Starting Passenger watchdog...
[ 2017-03-19 23:47:31.1052 25986/b6778700 age/Cor/CoreMain.cpp:1070 ]: Starting Passenger core...
[ 2017-03-19 23:47:31.1054 25986/b6778700 age/Cor/CoreMain.cpp:245 ]: Passenger core running in multi-application mode.
[ 2017-03-19 23:47:31.1255 25986/b6778700 age/Cor/CoreMain.cpp:820 ]: Passenger core online, PID 25986
[ 2017-03-19 23:47:31.1467 25999/b677c700 age/Ust/UstRouterMain.cpp:529 ]: Starting Passenger UstRouter...
[ 2017-03-19 23:47:31.1481 25999/b677c700 age/Ust/UstRouterMain.cpp:342 ]: Passenger UstRouter online, PID 25999
[ 2017-03-19 23:47:34.2566 25986/b64ffb40 age/Cor/SecurityUpdateChecker.h:464 ]: Security update check: no update found (next check in 24 hours)
App 26034 stdout: 
App 26113 stdout: 
[ 2017-03-19 23:47:48.4542 25986/b59feb40 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 1-1] Sending 502 response: application did not send a complete response
App 26034 stderr: [ 2017-03-19 23:47:48.4538 26113/0x84e5bbc(Worker 1) utils.rb:87 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 26113, thread 0x84e5bbc(Worker 1)):
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:513:in `validate_secret_key_config!'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:246:in `env_config'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/engine.rb:693:in `build_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:521:in `build_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/engine.rb:521:in `call'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
App 26034 stderr: [ 2017-03-19 23:49:39.9406 26113/0x84e5bbc(Worker 1) utils.rb:87 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 26113, thread 0x84e5bbc(Worker 1)):
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:513:in `validate_secret_key_config!'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:246:in `env_config'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/engine.rb:693:in `build_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:521:in `build_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/engine.rb:521:in `call'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
[ 2017-03-19 23:49:39.9408 25986/b517cb40 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 2-1] Sending 502 response: application did not send a complete response
App 26034 stderr: [ 2017-03-19 23:53:01.8904 26113/0x84e5bbc(Worker 1) utils.rb:87 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 26113, thread 0x84e5bbc(Worker 1)):
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:513:in `validate_secret_key_config!'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:246:in `env_config'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/engine.rb:693:in `build_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/application.rb:521:in `build_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/railties-5.0.0.1/lib/rails/engine.rb:521:in `call'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
[ 2017-03-19 23:53:01.8906 25986/b59feb40 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 1-2] Sending 502 response: application did not send a complete response
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
App 26034 stderr:   from /home/caiyuanmao/.rvm/gems/ruby-2.3.0@rails5/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
共收到 6 条回复
9442

😅 把错误仔细看一遍

De6df3
Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) 

看错误信息

96
9442flowerwrong 回复

就是看不明白才会问的😅 ,不过还是谢谢你

96
De6df3huacnlee 回复

我之前项目用的是rails2.3.4,没有见过这种错误。看来我还有不少知识要更新

96
29736gakki 回复

看了链接,才明白是怎么回事。十分感谢!(话说,要不是看了链接,我都不知道production还不能访问😂

不过还有一个问题想问。我刚才将默认的development的密钥拷贝到了production下一份。然后发现production模式下,页面可以正常访问了。但是我不是很明白这个密钥写在secrets.ym中和写在环境变量中,有什么区别?我拷贝一个密钥和生成一个密钥有什么区别?还有都说这个密钥是为了安全性,怎么体现出来的?

32 cym2015 关闭了讨论 3月26日 16:20
32 cym2015 重新开启了讨论 3月26日 16:21
32 cym2015 关闭了讨论 3月26日 16:21
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册