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

I am currently testing out nginx and have set up some virtual hosts by putting configurations for each virtual host in its own file in a folder called sites-enabled.

I then ask nginx to load all those config files using:

include       C:/nginx/sites-enabled/*.conf;

This is my current config:

http {
    server_names_hash_bucket_size  64;

    include       mime.types;
    include       C:/nginx/sites-enabled/*.conf;
    default_type  application/octet-stream;


    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        root         C:/www-root;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            index  index.html index.htm index.php;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }    

    }

    server{
        server_name  localhost;
    }
}

And this is one of the configs for a virtual host:

server {
        server_name testsubdomain.testdomain.com

        root C:/www-root/testsubdomain.testdomain.com;
}

The problem is that for testsubdomain.testdomain.com, I cannot get php scripts to run unless I have defined a location block with fastcgi parameters for it.

What I would like to do is to be able to enable PHP for all hosted sites on this server (without having to add a PHP location block with fastcgi parameters) for maintainability. This is so that if I need to change any fastcgi values for PHP, I can just change it in 1 location.

Is this something that's possible for nginx? If so, how can this be done?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I typically make a "global" folder in my conf.d folder inside of the Nginx config folder. And then create a php.conf file:

location ~ \.php$ {
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   include        fastcgi_params;
}

And then I just include all the configuration files in the virtual host:

include C:/nginx/conf.d/global/*.conf
share|improve this answer
    
Hi @TaylorJasko, I got "location" directive is not allowed here in /etc/nginx/conf.d/php.conf. Do you know why that is so? –  fuzzybee May 11 '13 at 5:31
1  
Hey @fuzzybee, sounds like you're including the files in the main nginx.conf. You'd want to include it on the vhost itself and have it have its own folder /etc/nginx/conf.d/global. So put that include line in your vhost (/etc/nginx/sites-enabled/your-vhost) and then it should work. Your /etc/nginx/nginx.conf probably has a line that reads include C:/nginx/conf.d/*.conf, and as no location directives are allowed there, it would make sense. –  Taylor Jasko May 11 '13 at 6:02

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.