Nginx - Enable PHP for all hosts

Posted by F21 on Server Fault See other posts from Server Fault or by F21
Published on 2012-12-10T03:59:22Z Indexed on 2012/12/10 5:07 UTC
Read the original article Hit count: 458

Filed under:
|
|

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?

© Server Fault or respective owner

Related posts about php

Related posts about nginx