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.

Many of the guides for setting up Wordpress (or similar applications) on nginx with php-fpm use a configuration that in part looks something like this:

 location    ~ [^/]\.php(/|$) {
              fastcgi_split_path_info ^(.+?\.php)(/.*)$;
              if (!-f $document_root$fastcgi_script_name) {
                #some guides suggest try_files $uri =404; instead
                return 404;
              }
              fastcgi_pass php;
              fastcgi_index index.php;
              include fastcgi_params;
  }

  #Route anything not otherwise matched
  location / {
      try_files $uri $uri/ /index.php$is_args$args;
  }

With this configuration if the requested URI /someuri isn't an actual location it'll get routed to index.php and from there to the backend.

The 404 part is there to prevent unauthorized code execution, so if the requested URI is /somefile.php which doesn't exist then a simple nginx 404 is generated.

What would be a better way to configure this (& remain 'secure') so that a request for a nonexistant php file also get passed to the backend via index.php?

share|improve this question
    
    
@MichaelHampton, thanks, that is one of the many guides I've looked at. –  matthew Apr 13 at 0:26
    
Not sure to understand...a request to a non-existant php file should even not be passed to the backend (imho - or i've missed something). Why do you want this behaviour ? –  krisFR Apr 13 at 0:32
    
@krisFR, FPM shouldn't try to execute the non-existant file. It should execute index.php which has error handling and other functions that are able to deal with the request. –  matthew Apr 13 at 1:06
    
hum...have you tried to remove the if statement ? –  krisFR Apr 13 at 1:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.