WordPress sub-directory on other server running on nginx?

Just for sharing my experience to others:

I have main site with domian.com and want to subdirectory domain.com/blog reverse proxy to blog.domain.com which is a wordpress with nginx! so this is how things work for me:

HTTP version:
1- in domian.com nginx config set /blog like this:

   listen 80;
   server_name domain.com www.domain.com;

   location / {

      root /path/file/content;
      index index.php index.html;


   }

   location /blog/ {
        proxy_set_header  Host               $host;
        proxy_set_header  X-Real-IP          $remote_addr;
        proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto  $scheme;
        proxy_pass http://blog.domain.com;
   }

}

2- in blog.domain.com setup normal nginx config and just add CORS in server block for loading fonts and other stuff:

    add_header 'Access-Control-Allow-Origin' "http://domain.com";
    add_header 'Access-Control-Allow-Methods' 'GET, POST';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
    add_header 'Referrer-Policy' 'origin';

3- go to admin panel in wordpress then in settings and change your parameters like:

wordpress Address: http://blog.domain.com
site Address: http://domain.com/blog

and you should be good now!

HTTPS version:

1- in server which blog.domain.com wordpress exist do certbot --nginx and make it https

2- next change domain’s nginx conf file like this:

   location /blog/ {
        proxy_set_header  Host               $host;
        proxy_set_header  X-Real-IP          $remote_addr;
        proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto  $scheme;
        proxy_pass https://blog.domain.com;
   }

3- you can do same for domain.com but I used CDN for make it https

4- go to admin panel in wordpress then in settings and change your parameters like:

wordpress Address: https://blog.domain.com
site Address: https://domain.com/blog

hope it helps you folks 😉