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.

In the lines below, I might have a site-specific configuration file that contains additional fastcgi_params unique to that site. If this file exists I want to load it.

server {
        listen 80 default;
        server_name _;
        root /path/www/$host;

        # Pass PHP scripts to php-fastcgi listening on port 9000
        location ~ \.php {
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;


                if (-f /path/www/$host/nginx.conf) {
                        include /path/www/$host/nginx.conf;
                }
        }
}

However, this doesn't work and the error I get is:

nginx: [emerg] "include" directive is not allowed here in ...

Update

I thought that rather than checking separatly, I could let include check for me.

server {
        listen 80 default;
        server_name _;
        root /path/www/$host;

        # Pass PHP scripts to php-fastcgi listening on port 9000
        location ~ \.php {
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;

                include /path/www/$host/*.nginx;
        }
}

However, this doesn't seem to be working.

share|improve this question
    
Did you find a solution to this problem? I'm in the same boat, and I'm wondering how you did this? –  jackweirdy Jan 29 '13 at 18:33
    
Sorry, I think I finally solved whatever the problem was a different way. –  Xeoncross Jan 29 '13 at 20:41

2 Answers 2

up vote 4 down vote accepted

include does its thing during server start - runtime variables like $host can't be used, nor is it able to be used in an if context, as you found out.

You'd need to split up the server blocks for different hosts. Sorry!

share|improve this answer

Well, this is rather old, but anyway, I found a work-around.

I have a setup with vhosts configured in this style:

/etc/nginx/sites-enabled/site.com.conf

Instead of checking if the file exists (which isn't possible), I simply do:

include /etc/nginx/sites-customizations/site.com.*.conf

This way I can simply create a file in the sites-customizations-folder, which by my convention, is named the same as the main configuration. The * works pretty much like the if, as it doesn't break if there is no extra configuration files. If you like, this also enables you to add multiple extra configurations in separate files.

share|improve this answer

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.