Global PHP Rule


#1

Hi,
Is there a way to specify a global PHP location rule? As you can see
below,
the PHP block is repeated which is no good.

domain1.tld

server
{
server_name domain1.tld;
root html/domain1;

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;
}
}

domain2.tld

server
{
server_name domain2.tld;
root html/domain2;

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;
}
}
Thank You.


#2

On Sun, May 3, 2009 at 5:06 PM, Mathew D.
removed_email_address@domain.invalid wrote:

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;
}
}

You can put these in fastcgi_params:

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Also you can put all the fastcgi_params globally on the http {} block.

I have done that, and it works well, there is some random situation
though where if I try to override a fastcgi_param somewhere else, all
of them get unset.


#3

Mathew D. wrote:

Hi,

Is there a way to specify a global PHP location rule? As you can see
below, the PHP block is repeated which is no good.

Best as I can tell from
http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_pass, that’s they way
it is.

fastcgi_pass

syntax: fastcgi_pass fastcgi-server

default: none

context: location, if in location

Directive assigns the port or socket on which the FastCGI-server is
listening. Port can be indicated by itself or as an address and
port, for example:

  fastcgi_pass   localhost:9000;

using a Unix domain socket:

  fastcgi_pass   unix:/tmp/fastcgi.socket;

fastcgi_index index.php;

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

Thank You.

Jim


#4

I guess I’ll live with it for now.

The idea was to not repeat this data so it’d be easier to setup PHP on a
variety of domains without repetition. Maybe Igor can look at this as a
new
feature request.

Thank You.

2009/5/4 Jim O. removed_email_address@domain.invalid


#5

On Mon, May 4, 2009 at 8:05 AM, Mathew D.
removed_email_address@domain.invalid wrote:

I guess I’ll live with it for now.
The idea was to not repeat this data so it’d be easier to setup PHP on a
variety of domains without repetition. Maybe Igor can look at this as a new
feature request.
Thank You.

you can also put the whole location block in a file then include it on
every vhost


#6

Michael S. wrote:

}
I have done that, and it works well, there is some random situation
though where if I try to override a fastcgi_param somewhere else, all
of them get unset.

Correct me if I’m wrong, but you still have to put

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;


}

for each server block where you want to configure php. Even if you are
able to put the fastcgi_pass directive into fastcgi_params, something I
haven’t tried, you’d still need

location ~ .php$ {

include fastcgi_params;
}

in any server block where you wanted to run run php scripts since
fastcgi_pass has to be in a location block.

Jim


#7

On Sun, May 3, 2009 at 5:56 PM, Jim O. removed_email_address@domain.invalid
wrote:

tried, you’d still need
yup. that’s the only piece that i need to specifically put.