Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx variables similar to SetEnv in Apache?

Tags:

nginx

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.
like image 390
Nacho B Avatar asked Nov 11 '11 19:11

Nacho B


People also ask

What is SetEnv in Apache?

SetEnv DirectiveSets an internal environment variable, which is then available to Apache HTTP Server modules, and passed on to CGI scripts and SSI pages.

Can Nginx use environment variables?

Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But envsubst may be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts.


1 Answers

location / { ...    fastcgi_param   APPLICATION_ENV  production;    fastcgi_param   APPLICATION_CONFIG user; ... } 

but it's for PHP-CGI

like image 80
TREx Avatar answered Sep 18 '22 22:09

TREx