nginx rewrite does not work without "permanent" directive

Francis Daly francis at
Fri Dec 15 17:28:42 UTC 2017

On Fri, Dec 15, 2017 at 05:32:25PM +0300, Александр Трофимчук wrote:

Hi there,

> Nevertheless I wonder why the following (almost similar) config works?

I don't see it as similar. Am I missing something?

> I get php output when requesting for
> Though rewrite goes to another location with some additional parameters the
> configurations looks to me similar to one in the first message.

> Config that works(nginx 1.8):
> location ~ (\.php$|\.php/|\.php\?) {
> fastcgi_pass;
> fastcgi_index  index.php;
> include        fastcgi_params;
> set $path_info "";
> set $real_script_name $fastcgi_script_name;
> if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
>    set $real_script_name $1;
>    set $path_info $2;
> }
> fastcgi_param SCRIPT_FILENAME  $document_root$real_script_name;
> fastcgi_param SCRIPT_NAME $real_script_name;
> fastcgi_param PATH_INFO $path_info;
> fastcgi_param PATH_TRANSLATED $document_root$real_script_name;
> }

The configuration that did not work for you was

location ~ ^/www2/web/(app_dev|config)\.php(/|$) {
  fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  fastcgi_split_path_info ^(.+\.php)(/.*)$;
  include fastcgi_params;
  fastcgi_param  SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  fastcgi_param DOCUMENT_ROOT $realpath_root;

which looks very different from the location{} above that does work for you.

Both do a fastcgi_pass, so the real question is: what does your fastcgi
server do that is different between the two calls?

Which fastcgi_param values does your fastcgi server care about, and do
they have different values in the two cases?

Francis Daly        francis at

More information about the nginx mailing list