使用nginx / php-fpm设置$ _ENV(fka $ HTTP_ENV_VARS) [英] Setting $_ENV (fka $HTTP_ENV_VARS) with nginx/php-fpm

查看:314
本文介绍了使用nginx / php-fpm设置$ _ENV(fka $ HTTP_ENV_VARS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

apache环境中的setenv相当于什么?
使用apache,我可以设置envSOMEE​​NV,并通过$ _ENV ['SOMEE​​NV']访问php,但我不知道如何使用nginx + php-fpm。 p>

我最初以为我只需要在我的php-fpm池的配置中设置ENV [SOMENEV] = test,但是var_dump($ _ ENV)仍然没有返回任何内容。 p>

任何提示?

解决方案

nginx没有办法影响php的环境,因为它没有将php解释器嵌入到其进程中。它通过 fastcgi_param 指令将参数传递给php。您可以添加一个您设置其余参数的地方,并通过$ _SERVER进行访问:

  location〜\.php $ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $ request_filename;
fastcgi_param SOMEE​​NV测试;
fastcgi_pass php;
}


What is the equivalent of setenv in a apache environment? With apache I am able to for example set the env "SOMEENV" and access it in php via $_ENV['SOMEENV'] - but I have no idea how to do it with nginx+php-fpm.

I initially thought that I just have to set ENV[SOMENEV]=test in the config of my php-fpm pool, but var_dump($_ENV) still returns nothing.

Any hints?

解决方案

nginx doesn't have a way of affecting php's environment, since it doesn't embed the php interpreter into its process. It passes parameters to php through fastcgi_param directives. You can just add one where you set the rest of your params and access it via $_SERVER:

location ~ \.php$ {
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $request_filename;
  fastcgi_param SOMEENV test;
  fastcgi_pass php;
}

这篇关于使用nginx / php-fpm设置$ _ENV(fka $ HTTP_ENV_VARS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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