Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following nginx location block:

location ^~ /publish {

  #Allow home

  deny all;

Then this 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;
  include /etc/nginx/fastcgi_params;

The problem is that files inside of /publish like execute.php aren't being processed by the fastcgi PHP processor, they simply output the pure PHP code when called from CURL. How do I enforce the security rules defined in the /publish block but also still execute the PHP block if the file ends in .php?

share|improve this question

nginx only applies one location block to a request.

Use include if you'd like to share directives between blocks, or a try_files pointing to an @php location if you'd like to point multiple PHP-using location blocks to a single PHP handling location.

share|improve this answer
Shane, would you mind doing a gist or pastebin? Obviously I want to execute the PHP fastcgi block only if the file ends in .php, so how do I apply that location rule? – Justin Jul 17 '12 at 1:23
@Justin You'll need to provide some more context about your configuration. Do you have multiple different location blocks that you want to run PHP code in? – Shane Madden Jul 17 '12 at 1:34
Yes, multiple location blocks, which may contain PHP files. – Justin Jul 17 '12 at 1:37

Your Answer


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.