NGINX + Symfony – what is the internal directive redirecting to

configurationnginxsymfony

Over at the official NGINX docs, they have the following configuration for production-level Symfony:

# PROD
location ~ ^/app\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
   # When you are using symlinks to link the document root to the
   # current version of your application, you should pass the real
   # application path instead of the path to the symlink to PHP
   # FPM.
   # Otherwise, PHP's OPcache may not properly detect changes to
   # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
   # for more information).
   fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
   fastcgi_param DOCUMENT_ROOT $realpath_root;
   # Prevents URIs that include the front controller. This will 404:
   # http://domain.tld/app.php/some-path
   # Remove the internal directive to allow URIs like this
   internal;
}

The full configuration file can be found here

What is internal actually redirecting to? The comments say that it removes the front controller from the URI, but I'm not entirely sure how.

Best Answer

It doesn't redirect anything. It specifies how external redirections, i.e. locations like http://example.com/app.php/some-path should be handled; while set, they should return 404, only allowing internal redirections. Conditions handled as internal redirections are listed in the documentation for internal directive:

Specifies that a given location can only be used for internal requests. For external requests, the client error 404 (Not Found) is returned. Internal requests are the following:

  • requests redirected by the error_page, index, random_index, and try_files directives;
  • requests redirected by the X-Accel-Redirect response header field from an upstream server;
  • subrequests formed by the include virtual command of the ngx_http_ssi_module module and by the ngx_http_addition_module module directives;
  • requests changed by the rewrite directive.