nginx rewrite does not work without "permanent" directive

Alexander Trofimchouk alex.trofimchouk at gmail.com
Fri Dec 15 12:48:20 UTC 2017


Hello!

Please would you mind helping me.

My nginx rewrite works only if I add "permanent" directive. Without it there
is no rewrite seen even in browser's network log.

I have an image cache system which works this way:

- there is a folder for uploaded images ( )

- folder for small thumbnails of uploaded images ( )

- php script (Symfony controller).

If the user requests not yet existing thumbnail for already uploaded image,
than the php script is called and it generates a thumbnail and stores it in
a corresponding folder.

For example: User requests http://site.com/files/imagecache/thumb/1.jpg,
Nginx tries to find the file or redirects to
http://site.com/www2/web/app_dev.php/image/cache?path=thumb/1.jpg

But instead I get 404 not found /files/imagecache/thumb/1.jpg - this message
is provided by Symfony (PHP), not by nginx itself.

If I add "permanent" I get Symfony controller output in browser - which is
OK. What did I do wrong?

 

Full nginx config with folders, symfony config and ordinary php config
follows.

 

Thank you in advance!

 

server {

. 
            root /home/anima/projects/sfedu/sfedu-php;

...        

            # SYMFONY DEV

            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;

            }

            # PROD

            location ~ ^/www2/web/app\.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;

                                    internal;

            }

            location ~ ^/www2/web {

                        allow all;

                        try_files $uri /www2/web/app.php$is_args$args;

            }

            location ~ ^/www2 {

                        deny all;

            }

    # END OF SYMFONY BLOCK

 

    location ~ (\.php$|\.php/|\.php\?) {

                        fastcgi_pass   unix:/run/php/php7.0-fpm.sock;

                        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;

            }

 

    location /files/imagecache {

                        root    /home/anima/projects/http-upload;    

                        try_files $uri @imagecache;

            }

 

            location /files {

                        root    /home/anima/projects/http-upload;          

            }

 

            location @imagecache {

                        rewrite ^/files/imagecache/(.*)$
/www2/web/app_dev.php/images/cache?path=$1 permanent; #Here should be no
"permanent"

            }

 

}

 

 

Regards,

Alexander Trofimchouk.

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20171215/c00d33c5/attachment-0001.html>


More information about the nginx mailing list