I use SetEnv in Apache to set some variables in virtualhosts that I recover in PHP using $_SERVER[the_variable]
.
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?
Here is the background picture, just in case someone can suggest a better approach or my previous system does not work with Nginx.
- I use the same app for many domains. All data comes from different databases with the same structure.
- The database name is hardcoded to the virtual host, in that environmental variable.
- As I know the database name, all the queries go to its appropriate database, from the very first query.
- I can have multiple domains using the same database, just including the same variable into the directives.
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 newfastcgi_param
entry along with the rest of them. Wherever you're includingfastcgi_params
orfastcgi.conf
.but it's for PHP-CGI
You should keep in mind, that nginx doesn't manage php processes like apache does. You should config either php-fpm, or php-cgi, relying what runs php on your server.
php-cgi
php-fpm
The fastcgi_pass socket location needs to come first, then each of the fastcgi_param parameters. You can also list variables in a file in the nginx config folder, then include that file. The include file commonly has the name fastcgi_params. Your environment parameters can be added easily to the php handling block:
The fastcgi_params file located in the same directory as nginx.conf often looks like this: