Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Apache's module mod_env offers a handy way of setting environment variables in configuration files, like:

<VirtualHost *:80>
  DocumentRoot /var/www/rails_app/public
  PassengerAppRoot /var/www/rails_app
  SetEnv MY_VARIABLE contents

However, in nginx I couldn't find anything that serves the same purpose. What's the alternative here? I thought of setting environment variables in .profile files (I am using Ubuntu 10.04), but that wouldn't have the same "per vHost" isolation I have with Apache, right?

What are the alternatives here?

share|improve this question

FastCGI Param for fastcgi passing or Proxy Set Header for when proxy passing.

share|improve this answer

Why not just create a launcher script that sets the needed enviroment variables before it calls nginx or rails .. and have one scipt per instance?

share|improve this answer

fastcgi_params will allow you to set environment variables easily. Here's an example of adding environment variables using fastcgi params with php-fpm:

    location ~ \.php$ {
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  MY_VARIABLE     contents;
        include        fastcgi_params;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.