Need To Run Multiple Location Blocks

I have the following location blocks:

location ^~ /publish {
allow 127.0.0.1;

  #Allow home
  allow 99.100.101.102;

  deny all;
}

Then the following location block to process PHP after:

location ~\.php {
  try_files $uri =404;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_intercept_errors on;
  fastcgi_pass 127.0.0.1:9000;
  include /etc/nginx/fastcgi_params;
}

The problem is that a request to /publish/execute.php is only hitting
the first location block, and not hitting the fastcgi PHP execution
location block. How can I make the publish location block also check for
PHP files and if so, execute them according to the second location
block?

Thanks.

Posted at Nginx Forum:

On Tue, Jul 17, 2012 at 10:42 AM, justin [email protected] wrote:

The problem is that a request to /publish/execute.php is only hitting
the first location block, and not hitting the fastcgi PHP execution
location block. How can I make the publish location block also check for
PHP files and if so, execute them according to the second location
block?

Put another .php$ block inside the /publish block.

location ^~ /publish/ {

location ~ .php$ {

}
}

Edho,

Thanks for the reply. This is a bit sloppy though because let us assume
I have multiple publish location blocks. Copy and pasting the PHP
location block multiple times is bad practice, because if I need to make
changes, I have to update the PHP block multiple times. Is there a way
to make the PHP location block a variable and use it in multiple
locations?

Thanks much.

Posted at Nginx Forum:

So I pulled the PHP location block out, and put it in its own file
called php.conf. Then I simply did:

include /etc/nginx/php.conf

In each location block that needs to execute PHP. This seems to have
worked quite nicely. However, is there a better way of doing this?

Thanks.

Posted at Nginx Forum:

On Jul 18, 2012 6:12 AM, “justin” [email protected] wrote:

So I pulled the PHP location block out, and put it in its own file
called php.conf. Then I simply did:

include /etc/nginx/php.conf

In each location block that needs to execute PHP. This seems to have
worked quite nicely. However, is there a better way of doing this?

AFAIK, that’s the best way.