无法使用 Nginx 部署 Passenger

Cant deploy Passenger with Nginx

我一直在关注this tutorial to deploy Phusion Passenger with Nginx, and after finishing, I still get an error when I open the URL with the IP address (http://123.123.123.123)

当我从 nginx 观看 error.log 时,我看到了这个:

http://pastie.org/pastes/10358955/text?key=s16vrhu2cofrian1hluwa

从那个日志中,我注意到了这一点:

Warning: compilation didn't succeed. To learn why, read this file: App 15789 stderr: /tmp/passenger_native_support-1g8vwu3.log

所以这是该文件的输出:

http://pastie.org/pastes/10358951/text

这里有什么问题?为什么我的 rails 应用无法运行?

您需要安装 javascript 运行时。最简单的解决方案是将 therubyracer 添加到您的 Gemfile。

# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby

根据日志,您似乎还需要安装 curl 或 wget。

实际上,问题不在于缺少 Javascript 运行时。虽然错误消息确实提到 "Could not find a JavaScript runtime",但 实际 问题是您的 PATH 环境变量设置不正确。

指标就在这两条看似不重要的错误信息中:

App 15789 stderr: sh: 1: 
App 15789 stderr: env: not found

env是一个通用的Unix命令,位于/usr/bin。 Node.js 以及几乎所有其他内容也位于 /usr/bin 中。如果系统找不到 env 那说明你的 PATH 环境变量没有设置正确。

之所以设置不正确,很有可能是因为Nginx nuked your environment variables。尝试将此添加到您的 Nginx 配置文件中:

# Don't nuke PATH; preserve original value.
env PATH;