Nginx – Rewrite nginx rule for for a directory to another domain/sub domain

nginxredirectrewrite

i have setup the following nginx rewrite rule . But doesn't seems to be working,

*

location /images {
       rewrite ^(.*)$1 http://sub.domain.com/$1 permanent;
}

*

for images i'm trying to redirect to another domain. How could i make this work ?

Best Answer

You don't need regex capture here. Try this:

location /images {
    rewrite ^ http://sub.domain.com$request_uri permanent;
}