Nginx port to subfolder reverse proxy

/etc/nginx/conf.d/example.com.conf
server {
    listen 80;

    index index.html index.htm index.nginx-debian.html index.php;

    server_name example.com;

    location ~/app2(.*)$ {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass https://example.com:8001$1;
    }
}