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

In my nginx conf.d file I have the following:

  location ~ \.php$ {
    try_files $uri = 404;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

  location ^~ /dev/ {
    fastcgi_param PHP_VALUE display_errors=On;

My goal was to have it so *.php was parsed by PHP in any directory, including the /dev/ directory and that, within the /dev/ directory, display_errors would be enabled. But it seems that the locations aren't being ANDed together but rather ORd. So if it matches *.php it parses it as a PHP file unless it's in the /dev/ directory.

Do I have to be redundant and have the PHP config code duplicated twice or is there a way I can avoid that redundancy?


share|improve this question

Yes, you have to be redundant. Except in very limited circumstances, location blocks are only parsed once, and the closest match wins.

Though you can reduce the pain of this by removing the common configuration parameters to a separate file and then using include to include it in both places.

share|improve this answer

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.