如何将ImageMagick环境变量传递给nginx mongrels?

时间:2010-03-22 13:55:09

标签: ruby-on-rails nginx environment-variables imagemagick mongrel

我的Rails应用程序使用ImageMagick,但应用程序在尝试执行ImageMagick命令(“识别”)时失败。我通过在Apache配置中传递以下环境变量来解决开发中的这个问题(我正在运行Apache / Passenger):

  SetEnv MAGICK_HOME /opt/local/var/macports/software/ImageMagick/6.5.9-0_0+q16
  SetEnv DYLD_LIBRARY_PATH /opt/local/var/macports/software/ImageMagick/6.5.9-0_0+q16/opt/local/lib
  SetEnv PATH /usr/bin:/opt/local/var/macports/software/ImageMagick/6.5.9-0_0+q16/opt/local/bin

但是,我的生产环境正在运行Nginx和Mongrel(不是我设置的),我不知道如何将这些变量传递给应用程序。我的nginx.conf文件目前如下:

# user and group to run as
user  mouthbreather mouthbreather;

worker_processes  4;

# pid of nginx master process
pid /var/run/nginx.pid;

events {
  worker_connections  8192;
  use epoll;
}

http {

  include /etc/nginx/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  /var/log/engineyard/nginx/access.log  main;
  error_log  /var/log/engineyard/nginx/error.log notice;

  sendfile on;

  tcp_nopush        on;
  tcp_nodelay       on;

  gzip              on;
  gzip_http_version 1.0;
  gzip_comp_level   2;
  gzip_proxied      any;
  gzip_buffers      16 8k;
  gzip_types        text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

  include /etc/nginx/sites/*.conf;
}

所以我的问题是:

  1. 如何确定我的MAGICK_HOME在制作中的位置?
  2. 如何通过nginx.conf将这些变量传递给应用程序?
  3. 谢谢!

1 个答案:

答案 0 :(得分:4)

简而言之,你没有通过nginx通过环境变量传递任何东西,你使用HTTP头或fastcgi参数。

在您的情况下,您甚至不需要,因为您正在正确地执行操作并将mongrels作为单独的进程运行 - 在环境中设置环境变量。 Nginx与它无关。

Nginx不能与环境变量一起使用,并且可能在很长一段时间内不会有人错误地将第三方模块一起攻击它,然后它仍然不会在主流中支持。

这有很多原因,主要是设计,安全性,管理相关,但最终开发人员和社区的意见是,当HTTPd设计用于处理环境变量时,不是HTTPd的位置可能不在同一台机器上的资源(如何将环境变量传递给在附近另一台机器上侦听的进程?)。

此外,乘客是第三方模块,在实现和设计方面都有所不同,因为它违背了nginx的设计目标,因为它在nginx中运行应用程序进程(这里你可以传递环境变量)理论上,但这不是nginx的工作方式。)

处理这类事情的推荐方法是在nginx之外启动你的应用程序(如果你愿意,可以在那里使用环境变量),然后将proxy或fastcgi传递给你的应用程序,可选地包括在header或fastcgi params中必要的额外数据。或者,您的应用程序可能有某种方法来确定其中的正确设置,例如settings.local文件(这在python设置中相当常见)。

如果没有nginx处理环境变量,有很多方法可以做到这一点。