Linux 在阿里云部署 Rails 时,总是出现:We're sorry, but something went wrong

hofffmancx · 2017年06月06日 · 最后由 ringokun 回复于 2017年06月07日 · 8653 次阅读

在阿里云上部署 rails 时,总是出现:We're sorry, but something went wrong。

重装了五遍系统,谷歌尝试多次,但是仍然报错。

所以发帖请求大神们的帮助。非常感谢。

版本信息:

  1. 阿里云 ubuntu : 16.04.2 LTS
  2. ruby-2.3.1
  3. rails 5.0.3
  4. Phusion Passenger 5.1.4
  5. nginx version: nginx/1.10.3

配置信息:

  1. /etc/nginx/sites-enabled/myapp.conf
server {
    listen 80;
    server_name eyulaodu.com;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/myapp/code/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /usr/local/rvm/gems/ruby-2.3.1/wrappers/ruby;
}

2 . /etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";



     include /etc/nginx/passenger.conf;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
#}

3 . /etc/nginx/passenger.conf

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/local/rvm/gems/ruby-2.3.1/wrappers/ruby;

相关报错:

1 . sudo tail /var/log/nginx/error.log 后终端显示:

config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `eval'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'


[ 2017-06-06 12:32:48.1369 19796/7f20b7896700 age/Cor/Con/CheckoutSession.cpp:285 ]: [Client 1-15] Cannot checkout session because a spawning error occurred. The identifier of the error is 534dd085. Please see earlier logs for details about the error.

2 . sudo service nginx restart 重启服务器,再次运行 sudo tail /var/log/nginx/error.log 后终端显示:

[ 2017-06-06 12:46:42.4406 19802/7feb0a296780 age/Ust/UstRouterMain.cpp:523 ]: Passenger UstRouter shutdown finished
[ 2017-06-06 12:46:42.4663 19796/7f20be491780 age/Cor/CoreMain.cpp:1055 ]: Passenger core shutdown finished
2017/06/06 12:46:43 [info] 20926#20926: Using 32768KiB of shared memory for nchan in /etc/nginx/nginx.conf:71
[ 2017-06-06 12:46:43.4941 20935/7fd0a9296780 age/Wat/WatchdogMain.cpp:1281 ]: Starting Passenger watchdog...
[ 2017-06-06 12:46:43.5017 20938/7fd91419b780 age/Cor/CoreMain.cpp:1070 ]: Starting Passenger core...
[ 2017-06-06 12:46:43.5018 20938/7fd91419b780 age/Cor/CoreMain.cpp:245 ]: Passenger core running in multi-application mode.
[ 2017-06-06 12:46:43.5047 20938/7fd91419b780 age/Cor/CoreMain.cpp:820 ]: Passenger core online, PID 20938
[ 2017-06-06 12:46:43.5125 20944/7f5a4e2d9780 age/Ust/UstRouterMain.cpp:529 ]: Starting Passenger UstRouter...
[ 2017-06-06 12:46:43.5130 20944/7f5a4e2d9780 age/Ust/UstRouterMain.cpp:342 ]: Passenger UstRouter online, PID 20944
[ 2017-06-06 12:46:48.6531 20938/7fd9140ac700 age/Cor/SecurityUpdateChecker.h:356 ]: Security update check: no update found (next check in 24 hours)

3 . tail -f log/production.log 后显示:

D, [2017-06-05T21:46:47.385590 #18316] DEBUG -- :    (6.0ms)  commit transaction
I, [2017-06-05T21:46:47.385649 #18316]  INFO -- : Migrating to CreateGroupRelationships (20170531100224)
D, [2017-06-05T21:46:47.386154 #18316] DEBUG -- :    (0.0ms)  begin transaction
D, [2017-06-05T21:46:47.386869 #18316] DEBUG -- :    (0.2ms)  CREATE TABLE "group_relationships" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "group_id" integer, "user_id" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
D, [2017-06-05T21:46:47.387607 #18316] DEBUG -- :   SQL (0.1ms)  INSERT INTO "schema_migrations" ("version") VALUES (?)  [["version", "20170531100224"]]
D, [2017-06-05T21:46:47.397393 #18316] DEBUG -- :    (9.6ms)  commit transaction
D, [2017-06-05T21:46:47.399630 #18316] DEBUG -- :   ActiveRecord::InternalMetadata Load (0.1ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?  [["key", "environment"], ["LIMIT", 1]]
D, [2017-06-05T21:46:47.402587 #18316] DEBUG -- :    (0.0ms)  begin transaction
D, [2017-06-05T21:46:47.403546 #18316] DEBUG -- :   SQL (0.2ms)  INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["key", "environment"], ["value", "production"], ["created_at", "2017-06-05 13:46:47.402770"], ["updated_at", "2017-06-05 13:46:47.402770"]]
D, [2017-06-05T21:46:47.407726 #18316] DEBUG -- :    (4.0ms)  commit transaction

4 . systemctl status nginx.service 服务器状态:

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-06-06 13:06:25 CST; 2min 17s ago
  Process: 21188 ExecStop=/bin/sleep 1 (code=exited, status=0/SUCCESS)
  Process: 21183 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry TERM/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCE
  Process: 21200 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 21195 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 21223 (nginx)
   CGroup: /system.slice/nginx.service
           ├─21203 Passenger watchdog
           ├─21206 Passenger core
           ├─21212 Passenger ust-router
           ├─21223 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           └─21228 nginx: worker process

Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: Started A high performance web server and a reverse proxy server.

5 journalctl -xe

Jun 06 13:06:24 iZuf6fe5v25797lljd3j1zZ systemd[1]: Stopping A high performance web server and a reverse proxy server...
-- Subject: Unit nginx.service has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun shutting down.
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: Stopped A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has finished shutting down.
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: Starting A high performance web server and a reverse proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun starting up.
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ systemd[1]: Started A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has finished starting up.
--
-- The start-up result is done.
Jun 06 13:06:25 iZuf6fe5v25797lljd3j1zZ sudo[21176]: pam_unix(sudo:session): session closed for user root
Jun 06 13:15:01 iZuf6fe5v25797lljd3j1zZ CRON[21276]: pam_unix(cron:session): session opened for user root by (uid=0)
Jun 06 13:15:01 iZuf6fe5v25797lljd3j1zZ CRON[21277]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 06 13:15:01 iZuf6fe5v25797lljd3j1zZ CRON[21276]: pam_unix(cron:session): session closed for user root
Jun 06 13:17:01 iZuf6fe5v25797lljd3j1zZ CRON[21279]: pam_unix(cron:session): session opened for user root by (uid=0)
Jun 06 13:17:01 iZuf6fe5v25797lljd3j1zZ CRON[21280]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jun 06 13:17:01 iZuf6fe5v25797lljd3j1zZ CRON[21279]: pam_unix(cron:session): session closed for user root

先检测 passenger 是否正常工作

我隐约记得 passenger 好像和 nginx 搭配要重新编译一下

不嫌弃的话 试试 puma

Phusion Passenger 怎么安装的?

jicheng1014 回复

sudo /usr/sbin/passenger-memory-stats, 貌似正常的。
---------- Nginx processes -----------

PID PPID VMSize Private Name

21223 1 166.6 MB 0.6 MB nginx: master process /usr/sbin/nginx -g daemon on; master_process on; 21228 21223 166.6 MB 0.7 MB nginx: worker process Processes: 2 Total private dirty RSS: 1.32 MB

----- Passenger processes -----

PID VMSize Private Name

21203 433.2 MB 1.2 MB Passenger watchdog 21206 651.2 MB 3.3 MB Passenger core 21212 441.4 MB 1.3 MB Passenger ust-router Processes: 3 Total private dirty RSS: 5.80 MB

kikyous 回复

根据官方教程,安装的:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7

sudo apt-get install -y apt-transport-https ca-certificates

sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'

sudo apt-get update

sudo apt-get install -y nginx-extras passenger

看看环境变量有没有配置。

passenger 在 nginx 有一个运行环境设置 rails_env。你可以远程进一下 console 看看是什么环境运行的

查一下 /var/log/nginx/error.log,passenger 启动需要额外安装 passenger native support,阿里云上因为是只读的文件系统可能会出错

sudo apt-get update的时候,有没有遇到这个问题:

E: Failed to fetch https://oss-binaries.phusionpassenger.com/apt/passenger/dists/xenial/main/binary-amd64/Packages Bad header line

ringokun 回复

墙的问题

config 有调试开关打开,可以看到具体的错误。或者看 log。

huacnlee 回复

谢谢,确实是这个问题。

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