Coming from 15+ years of using Apache's web server, I wanted to give the new kid a chance. ;) I have been trying to tweak my NGINX configuration files for brevity.

The site generally rewrites all the traffic to a specific index.php, but I have two directories privacy and eula which contain individual index.phps, so for those two directories I want it to just call the files in the directories.

For example:

location ~ /(privacy|eula) {
  try_files $uri $uri/ =404;

causes my browser to download the pages content as a .dms file.

If I split the location into two like so:

location /privacy {
  try_files $uri $uri/ =404;

location /eula {
  try_files $uri $uri/ =404;

It works as intended.

I searched and also found the suggestion to do it this way, but that had the same effect location ~ ^/(privacy|eula). Do I just have to live with the fact that NGINX is very verbose, or what am I doing wrong?



The regular expression location blocks are evaluated in order until a match is found.

In your case, you have placed location ~ /(privacy|eula) above the location ~ \.php$ block, so that a URI like /eula/index.php will not be processed by the correct location and will be downloaded instead.

Place the location ~ /(privacy|eula) block after the location ~ \.php$ block.

See this document for details.

  • aahhh... thanks! – Joseph Jul 23 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.