如何将ImageMagick环境变量传递给nginx mongrels? [英] How do I pass ImageMagick environment variables to nginx mongrels?

查看:174
本文介绍了如何将ImageMagick环境变量传递给nginx mongrels?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My Rails app makes use of ImageMagick, but the app fails on trying to execute the ImageMagick command ("identify"). I fixed this issue in development (where I'm running Apache/Passenger) by passing the following environment variables in my Apache config:

  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文件目前如下:

However, my production environment is running Nginx and Mongrel (not something I set up), and I am not sure how to pass those variables to the app. My nginx.conf file currently is as follows:

# 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将这些变量传递给应用程序?
  1. How can I determine where my MAGICK_HOME is on production?
  2. How can I pass those variables to the app via nginx.conf ?

谢谢!

推荐答案

你不会通过环境变量通过nginx传递任何东西,你使用HTTP头或fastcgi参数。

In short, you don't pass anything via environment variables with nginx, you use HTTP headers or fastcgi parameters.

在你的情况下,你甚至不需要,因为你是正确处理事情并运行mongrels作为一个单独的过程 - 在环境环境中设置环境变量。 Nginx与它无关。

In your case, you don't even need to, because you are doing things properly and running mongrels as a separate process - set the environment variables in THEIR environment. Nginx properly has nothing to do with it.

Nginx不适用于环境变量,可能不会很长时间,直到有人错误地将第三方模块与它仍然不会被支持在主流。

Nginx does not work with environment variables and probably will not for a very long time until someone mistakenly hacks a third party module together for it, and then it still won't be supported in the main stream.

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

There are a multitude of reasons for this, mostly design, security, administration related, but ultimately it's opinion of the developer and the community that dealing with environment variables is not the place of the HTTPd when the HTTPd is designed to work with resources that might not be on the same machine (how do you pass environment variables to processes listening on another machine nearby?).

此外,乘客是第三方模块,在实施和设计方面有些破裂,因为它是针对nginx设计的因为它运行在nginx中的应用程序进程(这里你可以在理论上传递环境变量,但是这不是nginx的工作方式)。

Furthermore, passenger is a third party module and is somewhat broken in terms of both the implementation and the design, in that it is against what nginx is designed for because it runs the application processes within nginx (here you COULD pass environment variables in theory, but it's not the way nginx is meant to work).

这样处理这些事情的推荐方法是在nginx之外启动应用程序(利用环境变量如果你愿意),然后代理或fastcgi传递到您的应用程序,可选地包括在标题或fastcgi参数中必要的额外数据。或者,您的应用程序可能有一些方法来确定其中的正确设置,例如settings.local文件(这在python设置中相当常见)。

The recommended method to handle things such as this is to start your application outside of nginx (making use of environment variables there if you wish) and then either proxy or fastcgi pass to your application, optionally including in headers or fastcgi params the necessary extra data. Alternatively, your application may have some way to determine proper settings within it, such as a settings.local file (this is fairly common in python setups).

有吨没有nginx处理环境变量的方法。

There are tons of ways to do this without having nginx deal with environment variables.

这篇关于如何将ImageMagick环境变量传递给nginx mongrels?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆