Open dschense opened 5 years ago
I have an idea. Install nginx on the vps and configure it as a reverse proxy
location / {
proxy_pass http://10.8.0.2:80/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
The source IP of the user will be in the X-Real-IP
header. I added X-Forwarded-For
for proxies but it's not necessary.
First of all, nice script. Its working good here. I just have a question if iam doing this the right way:
I am running the openvpn server on a debian 9 vps with one public ip "123.123.123.1" on eth0.
the vps is connected to my home network over tun0 "10.8.0.0/24". the vps has ip "10.8.0.1" and home network client has "10.8.0.2". the vpn is connected and the machines can ping each other. So far so good.
Now i want to use the public ip of the VPN server on eth0 for the client machine inside the tunnel network. The best way Ive found, is to forward the ports to the client machine.
so Iam using this way:
iptables -t nat -A PREROUTING -p tcp --dport 80 -d 123.123.123.1 -j DNAT --to-destination 10.8.0.2:80
iptables -t nat -A POSTROUTING -p tcp --dport 80 -j MASQUERADE
iptables -t nat -A OUTPUT -p tcp --dport 80 -d 123.123.123.1 -j DNAT --to-destination 10.8.0.2:80
after this its possible to access the nginx webserver running on the client machine inside the tunnel network over the dns http://dns-of-vps.com pointing to the public ip of the VPS.
and to get the rules on boot, I changed the add-openvpn-rules.sh to
and the rm-openvpn-rules.sh to
The only problem with this setup is, on the client side I get the source ip from the server side in the logs. for example accessing the http://dns-of-vps.com pointing to the vps ip, the logs on the client side get the source ip of the vps at the tunnel side -> "10.8.0.1" and not the real source ip of the user. Is there a way to pass the real source ip through the tunnel?
Is this the right way of doing this, or is there a better way? Ive searching for this for hours and days, but the tutorials are not clear enough.