Nginx/Passenger与Rails应用程序错误

4

我刚刚使用Capistrano将代码部署到了一台运行Linux Server (14.04)、Nginx、PHP5-FPM(用于phpMyAdmin)、MySQL和Passenger的服务器上。

一切都很好,但是当我尝试从浏览器访问Rails应用程序时,出现了错误。我查看了Nginx日志,发现以下内容:

App 15973 stdout: 
App 15973 stderr:  [passenger_native_support.so] trying to compile for the current user (deploy) and Ruby interpreter...
App 15973 stderr:      (set PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0 to disable)
App 15973 stderr:      Warning: compilation didn't succeed. To learn why, read this file:
App 15973 stderr:      /tmp/passenger_native_support-a97tab.log
App 15973 stderr:  [passenger_native_support.so] not downloading because passenger wasn't installed from a release package
App 15973 stderr:  [passenger_native_support.so] will not be used (can't compile or download) 
App 15973 stderr:   --> Passenger will still operate normally.
App 16021 stdout: 

然后:

$cat /tmp/passenger_native_support-a97tab.log

# current user is: deploy
# mkdir -p /usr/lib/buildout/ruby/ruby-2.2.1-x86_64-linux
Encountered permission error, trying a different directory...
-------------------------------
# mkdir -p /home/deploy/.passenger/native_support/5.0.26/ruby-2.2.1-x86_64-linux
# cd /home/deploy/.passenger/native_support/5.0.26/ruby-2.2.1-x86_64-linux
# /home/deploy/.rbenv/versions/2.2.1/bin/ruby /usr/lib/src/ruby_native_extension/extconf.rb
/home/deploy/.rbenv/versions/2.2.1/bin/ruby: No such file or directory -- /usr/lib/src/ruby_native_extension/extconf.rb (LoadError)

有什么问题吗?

这是我的Nginx默认文件:

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    # root /usr/share/nginx/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.php index.nginx-debian.html;

    server_name _;

    passenger_enabled on;
        rails_env    development;
        root         /home/deploy/highschool/current/public;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          root /usr/share/nginx/html;
    }

    location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
    }
}

以下是我的Nginx.conf文件:

user www-data;
worker_processes 4;
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;

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


    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Phusion Passenger config
    ##
    # Uncomment it if you installed passenger or passenger-enterprise
    ##

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /home/deploy/.rbenv/shims/ruby;

    # passenger_ruby /usr/bin/passenger_free_ruby;

    ##
    # Virtual Host Configs
    ##

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

我使用RBENV管理Ruby版本。

抱歉我的英语不好。


我也遇到了同样的问题已经有一个星期了。 - Shubham Abrol
今天我在使用 https://github.com/sandrew/from-scratch 进行全新安装时遇到了完全相同的问题。结果发现 Passenger 仍然尝试使用 passenger_ruby /usr/bin/passenger_free_ruby,因为我定义了两次。不确定这是否是我所做的全部,但一旦我删除了双重条目并重新启动,一切就开始正常工作了。 - Cory Loken
我成功修正了错误并启动了我的应用程序。 - Dvex
我成功修正了错误并启动了我的应用程序。 - Dvex
我之前一直遇到错误,因为我的SASS文件中有一个错误,并且我的SECRET_KEY也没有与devise配置。但是经过深入调试和检查nginx+passenger日志数小时后,我找到了这两个错误。现在我已经修复了这些错误,一切都正常运行。 - Shubham Abrol
2
5.0.26版本中存在一个错误,导致这种情况发生,该错误预计将在5.0.27中修复。请在此处关注:https://github.com/phusion/passenger/issues/1778 - bensie
1个回答

1
我找到了解决方案。
在我的服务器中,我在Rails应用程序中运行了以下命令:$ passenger-config build-native-support。 编译成功后,它向我显示了ruby_native_extension/extconf.rbruby_native_extension目录的真实路径。
我只需从/usr/lib/src/创建一个符号链接到ruby_native_extension目录并重新启动Nginx即可。
这样做后错误消失了,但是登录(devise)不起作用,总是出现404错误。 因此,(如果有任何情况发生)我专门为sign_in路由添加了一些行。
在我的Nginx默认文件中,我添加了以下内容:
location /users/sign_in {
  passenger_enabled on
}

并编辑:

location / {
   # First attempt to serve request as file, then
   # as directory, then fall back to displaying a 404.
   passenger_enabled on
   try_files $uri $uri/ =404;
}

随着这些更改,我的Rails应用程序正在运行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接