My local machine does not have a public IP and the IT department cannot setup an NAT for me, I want to setup a proxy on my remote public server which will forward the request to my local server.

I try using privoxy + ssh, but it says invalid header.

Step 1: open a ssh tunel by

ssh -nNT -R 8081:localhost:8080 user@example.com

Step 2: On the remote machine, configure a privoxy config, I tried

forward-socks5 / .


forward /

both said invalid header in browser


You are not opening any tunnel using:

ssh -R -nNT 8081:localhost:8080 user@example.com

but it should fail.

It should be

ssh -nNT -R 8081:localhost:8080 user@example.com

and it is called remote port forwarding.

  • sorry, that's a typo – cgcgbcbc Jul 15 '16 at 11:49

After some investigation, I found the reason:

Privoxy is not suitable for such an reverse proxy job, and ssh forward can only accept local traffic.

So there are 2 approaches for solving this problem:

  1. setup iptables rule for tcp forwarding (I'm not professional on this, but I think it's possible)

  2. setup a reverse proxy forwarding request to ssh forwarding port, this can be done through nginx, or write a simple one by oneself, for example, using go:


package main
import (

func main() {
    target, _ := url.Parse("http://localhost:8081")
    proxy := httputil.NewSingleHostReverseProxy(target);
    http.Handle("/", proxy)
    log.Fatal(http.ListenAndServe(":8080", nil))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.