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

I have the following nginx location block:

location ^~ /publish {
  allow 127.0.0.1;

  #Allow home
  allow 99.100.101.102;

  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;
  fastcgi_pass 127.0.0.1:9000;
  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?

Thanks.

share|improve this question

1 Answer 1

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

 
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.