Nginx rewrite rule question – Stack Exchange of Webmasters

I have a server with several domains on it.

One of these domains that I have to redirect to another domain, which is on a different server, but I want to let the request to / wp-admin / on this area.

For example, suppose the domain is mydomain.xxx

I want all the requests to www.mondomaine.xxx/wp-admin/ to be accepted and processed by the nginx server in question. Also, www.mydomain.xxx/wp-login.php ... must be accepted. All that is required for mydomain.xxx or www.mondomaine.xxx should be redirected to https://myotherdomain.xxx.

For example, www.mondomaine.xxx and mydomain.xxx and (www) .mydomain.xxx / something else (except / wp-admin / and wp-login.php ...) should be redirected. Where the demand is redirected, it is not necessary to include in the rewrite anything that could have been placed after the domain name. So in the case of mydomain.xxx/folder1/ the / folder1 / part can be completely ignored.

Currently I have server_name www.mydomain.xxx and mydomain_server_name.xxx to be listened to, and then I have:

if ($ host = www.mydomain.xxx) {
rewrite ^ / $ https://www.myotherdomain.xxx permanent;
}

But obviously that does not allow www.mondomaine.xxx/wp-admin/ pass through.

In addition, requests for www.mondomaine.xxx/wp-login.php? ... will need to pass too.

What is the best way to achieve this?