You can use socat.
Nginx config:
location / {
proxy_pass http://127.0.0.1:81/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
Socat command:
socat tcp4-LISTEN:81,reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:127.0.0.1:yourtordomain.onion:80,socksport=9050
Update:
If you want run socat as daemon. Create file socat.sh and set permission to 744:
#!/bin/bash
socat tcp4-LISTEN:81,reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:127.0.0.1:yourtordomain.onion:80,socksport=9050
And run it over screen:
screen -A -m -d -S SOCAT_DAEMON ./socat.sh