nginx rewrite does not work without "permanent" directive
Александр Трофимчук
alex.trofimchouk at gmail.com
Fri Dec 15 14:32:25 UTC 2017
Thank you for advice!
I will add the "redirect".
Nevertheless I wonder why the following (almost similar) config works?
I get php output when requesting for
http://site.com//files/imagecache/small/1.jpg
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 127.0.0.1:9002;
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 /.mnt/www-sfedu-data;
try_files $uri @imagecache;
}
location /files {
root /.mnt/www-sfedu-data;
}
location @imagecache {
rewrite ^/files/imagecache/(.*)$ /php_j/imagecache/index.php?q=$1; #no
permanent or redirect here !
}
Thank you in advance!
Regards,
Alexander Trofimchouk
2017-12-15 16:18 GMT+03:00 Francis Daly <francis at daoine.org>:
> On Fri, Dec 15, 2017 at 03:48:20PM +0300, Alexander Trofimchouk wrote:
>
> Hi there,
>
> > My nginx rewrite works only if I add "permanent" directive. Without it
> there
> > is no rewrite seen even in browser's network log.
>
> http://nginx.org/r/rewrite
>
> "rewrite" does not directly lead to "http redirect" without specific
> configuration.
>
> > 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
>
> No, that's not what your config says.
>
> nginx *rewrites* to /www2/web/app_dev.php/images/cache?path=thumb/1.jpg
>
> That rewritten request (depending on the omitted config) probably is
> handled within
>
> location ~ ^/www2/web/(app_dev|config)\.php(/|$) {
>
> which does the fastcgi_pass to PHP.
>
> If you want nginx to *redirect*, you have to tell it to, using one of
> the three documented methods.
>
> > If I add "permanent" I get Symfony controller output in browser - which
> is
> > OK. What did I do wrong?
>
> You left off "permanent" or "redirect" or didn't start the replacement
> string with "http://", if you wanted nginx to issue a redirect.
>
> f
> --
> Francis Daly francis at daoine.org
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20171215/3fcd7c2c/attachment.html>
More information about the nginx
mailing list