Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am starting a project that uses environment variables to set the database connection and a couple other things. (They didn't want to use configuration files since people are careless and overwrite them).

Anyway, I am using nginx and while it supports env - it doesn't seem to support it well enough. You can't set the env values on a per-server block basis. In other words, this won't work:

server {
    listen 80;
    server_name domain;
    env FOO = "bar";
}

You must do this:

env FOO = "bar";

http {
    server {
        listen 80;
        server_name domain;
    }
}

Which means that I can't have vhost-specific values. So I must create a whole vhost config for each site and only activate the one I want at the moment so that the value is set correctly.

Is there any way to work around this?

share|improve this question
    
Isn't the nginx config just as susceptible to overwriting as the application's config? What module is it using to feed requests to the application? –  Shane Madden Jan 19 '12 at 22:36
    
@ShaneMadden, the nginx config isn't part of the project but must be created on each server manually. So it won't be overwritten. What I posted isn' the full configs - we are also just using standard fastcgi_pass to forward the request to ruby/php. –  Xeoncross Jan 19 '12 at 22:40
add comment

1 Answer

up vote 2 down vote accepted

It turns out that if you are using fastcgi you can get around this by passing the values from fastcgi_param.

server {
    listen 80;
    server_name domain;

    # Pass PHP scripts to php-fastcgi listening on port 9000
    location ~ path/to/it {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param FOO "bar";
    }
}
share|improve this answer
    
Yup, that's what I was about to suggest. Beat me to it! (I'm out of votes for today, I'll upvote this answer in a bit) –  Shane Madden Jan 19 '12 at 23:01
    
@ShaneMadden perhaps you could help me with this. –  Xeoncross Jan 19 '12 at 23:12
add comment

Your Answer

 
discard

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.