Nginx 变量类似于 Apache 中的 SetEnv? [英] Nginx variables similar to SetEnv in Apache?

查看:34
本文介绍了Nginx 变量类似于 Apache 中的 SetEnv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Apache 中使用 SetEnv 在虚拟主机中设置一些变量,我使用 $_SERVER[the_variable] 在 PHP 中恢复这些变量.

I use SetEnv in Apache to set some variables in virtualhosts that I recover in PHP using $_SERVER[the_variable].

现在我正在切换到 Perl Catalyst 和 Nginx,但 Nginx 中的env"指令似乎不一样.这是行不通的.如何实现?

Now I am switching to Perl Catalyst and Nginx, but it seems that the "env" directive in Nginx is not the same. It does not work. How can it be accomplished?

这是背景图片,以防万一有人可以提出更好的方法,或者我以前的系统不适用于 Nginx.

Here is the background picture, just in case someone can suggest a better approach or my previous system does not work with Nginx.

  • 我对许多域使用相同的应用程序.所有数据都来自具有相同结构的不同数据库.
  • 数据库名称被硬编码到虚拟主机的环境变量中.
  • 因为我知道数据库名称,所以从第一个查询开始,所有查询都会转到相应的数据库.
  • 我可以有多个域使用同一个数据库,只需在指令中包含相同的变量即可.

推荐答案

NGINX 不像 apache 那样管理你的后端进程,所以它不会影响它们的环境.要从 NGINX 设置新的 $_SERVER PHP 变量,您需要添加一个新的 fastcgi_param 条目以及其余的条目.无论您在何处包含 fastcgi_paramsfastcgi.conf.

NGINX doesn't manage your backend processes like apache does, so it can't affect their environments. To set a new $_SERVER PHP variable from NGINX, you need to add a new fastcgi_param entry along with the rest of them. Wherever you're including fastcgi_params or fastcgi.conf.

这篇关于Nginx 变量类似于 Apache 中的 SetEnv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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