NGINX 和配置文件中的环境变量
我正在尝试通过 nginx 的配置文件为它设置一些环境变量。我正在使用 nginx/0.8.53 但它不起作用。
server {
listen 80;
server_name localdictus;
root /opt/vdmo_dictus/public; # <--- be sure to point to 'public'!
passenger_enabled on;
rails_env development;
env VDMO_MANDANT = "somevalue";
}
这是错误消息:
unknown directive "env" in /opt/nginx/conf/nginx.conf:43
文档告诉我有一个“env”命令...那么我做错了什么? http://wiki.nginx.org/CoreModule#env
通过导出设置环境变量顺便说一句,shell 不适合我的应用程序。
以下是:
37: server {
38: listen 80;
39: server_name localdictus;
40: root /opt/vdmo_dictus/public; # <--- be sure to point to 'public'!
41: passenger_enabled on;
42: rails_env development;
43: env VDMO_MANDANT = "somevalue";
44: }
问候,
亚历克斯
I'm trying to set some environment variables to nginx via it's configuration file. I'm using nginx/0.8.53 and it's not working.
server {
listen 80;
server_name localdictus;
root /opt/vdmo_dictus/public; # <--- be sure to point to 'public'!
passenger_enabled on;
rails_env development;
env VDMO_MANDANT = "somevalue";
}
This is the error message:
unknown directive "env" in /opt/nginx/conf/nginx.conf:43
The documentation tells me that there is an "env" command... so what I'm doing wrong ??
http://wiki.nginx.org/CoreModule#env
setting the environment variables via export on the shell is not an option for my application by the way.
Here are the lines:
37: server {
38: listen 80;
39: server_name localdictus;
40: root /opt/vdmo_dictus/public; # <--- be sure to point to 'public'!
41: passenger_enabled on;
42: rails_env development;
43: env VDMO_MANDANT = "somevalue";
44: }
Regards,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从链接到
env
指令的“上下文”的文档中是main
,而不是server
。将指令放在server { ... }
块之外(任何块之外)。另请参阅此讨论。我不相信
env
指令可以满足您的要求。From the documentation you linked to the "Context" for the
env
directive ismain
, notserver
. Put the directive outside of yourserver { ... }
block (outside of any block).See also this discussion. I do not believe that the
env
directive does what you are looking for.不要传递 env 指令。只需在启动 nginx 时使用
-E
标志即可:Don't pass the env directive. Just use the
-E
flag when starting nginx:使用 nginx 为 Rails 应用程序设置环境变量的解决方案。
例如,您的 RAILS_ROOT 是: /opt/myapp_MANDANT
然后以下代码将从 RAILS_ROOT 路径中提取 MANDANT 并将其设置到 Rails 环境中。
将此代码放入您的environment.rb 文件中即可工作。
使用此方法的一个好方法是使用 --bind 选项进行挂载。
示例:
然后将 Rails 应用程序的公共路径设置为 /originalsource/public/ 而不是 /railsapp_mandant/public/
A solution for setting the environment variables for a rails app using nginx.
Your RAILS_ROOT , for example, is : /opt/myapp_MANDANT
Then the following code would extract MANDANT from the RAILS_ROOT path and set in to the rails env.
put this code in your environment.rb file to work.
A nice way for using this approch is mount with the --bind option.
Example:
then set the public path of the rails app to to /originalsource/public/ instead of /railsapp_mandant/public/