3

The following makes nginx not to pass to the PHP-FPM fastcgi server because I created a location block:

location = /test.php { auth_basic "Nope."; auth_basic_user_file /test.htpasswd; } location ~* \.php$ { try_files $uri =404; include params/fastcgi; fastcgi_keep_conn on; fastcgi_index index.php; fastcgi_pass 127.0.0.1:4623; } 

Means: if the first location block matches, it seems that the second one is ignored. Is there any solution for this without copying the fastcgi-stuff from the second location block into the first one?

3
  • Would you mind to show example request where the problem is present? The first will match domain/test.php. The rest of the php should be handled by the other location. I would like to see how are u testing this conf. Commented Mar 29, 2014 at 17:48
  • I test it by calling test.php and seeing that the php code appears in my browser ;-) All other php files work. Commented Mar 29, 2014 at 23:49
  • nginx.org/en/docs/http/request_processing.html Commented Mar 30, 2014 at 13:04

1 Answer 1

1

I'd put all your fastcgi configuration on a file and include it on both locations.

Things like nested locations may prone your configuration buggy and more difficult to understand and maintain.

Sign up to request clarification or add additional context in comments.

3 Comments

Is this the correct solution? Is there no way to say 'hey, please look at other location blocks too?
Check the following link: nginx.org/en/docs/http/request_processing.html . Thee you will find that "...nginx first searches for the most specific prefix location given by literal strings regardless of the listed order...". You are using the "/test.php" literal and nginx wont match any other location.
Thanks, seems to be best practice to do so.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.