0

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 / 127.0.0.1:8081 .
listen-address 0.0.0.0:8080

and

forward / 127.0.0.1:8081
listen-address 0.0.0.0:8080

both said invalid header in browser

0

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
0

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:

e.g.

package main
import (
    "net/http/httputil"
    "net/http"
    "net/url"
    "log"
)

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.