0

I have been able to set up my virtual machine on google cloud platform and am able to SSH into my RPi successfully using this tutorial:

https://medium.com/jj-innovative-results/how-to-access-a-raspberry-pi-anywhere-with-reverse-ssh-and-google-cloud-platform-59b6a89501a

Now I want to transfer HTTP data on port 8080 where my LAN application is hosted on the RPi instead of SSH data on port 22 to my virtual machine. How do i go about this and is it possible?

From there i plan on buying a domain to view my LAN app on the internet. I don't want to use services such as remoteit/zerotier to do this

Please help

1 Answers1

0

For security reasons, I am recommending setting up a proxy between the Internet and your SSH server. You can skip steps #1 and #2 and use a port number above 1024 such as 8080. Never run the SSH server directly on port 80 as that requires privilege.

STEP 1)

Install Apache or Nginx.

STEP 2)

Set up a proxy in Apache/Nginx to forward connections on port 80 to port 8080.

Example configuration for Nginx:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         "http://127.0.0.1:8080";
    }
}

STEP 3)

Configure the VM SSH server to allow port forwarding option AllowTcpForwarding.

Setup the tunnel to open port 8080 on the VM and forward to the listening port on your Raspberry Pi (example 9000).

Example SSH command to run on the raspberry Pi:

ssh -R 8080:127.0.0.1:9000 <VM IP Address> <Your credentials>

Details. This command opens port 8080 on the public VM server and forwards traffic back to your system to port 9000.

Note: I did not test the SSH command, but this should be correct. There are many examples on the Internet such as link. This answer will help you understand how traffic is routed (forwarded).

STEP 4)

Configure the application running on the Raspberry Pi to listen on port 9000 (example).

Summary, the client connects to VM port 80 which forwards to VM port 8080 which forwards over the SSH tunnel to the Raspberry Pi which has an application listening on port 9000.

Of course, you can change the port numbers, I used unique port numbers to prevent confusion.

John Hanley
  • 74,467
  • 6
  • 95
  • 159
  • Your solution does not work yet I just love the way you explain this. Maybe you could help me since I am completely lost. I have a local express app (raspberry PI) running on port 5000. I have a working instance of GCP VM that runs at let's say 34.000.00.00. So I am using this command: ssh -R 5005:34.000.00.00:5000 xx@34.000.00.00 - and based on what I understand - I am opening the tunnel on 34:000.00.00:5005 and this tunnel should contain what I have on my Raspberry PI which is running on localhost:5000... I allowed firewall on GCP for 5000-5100 yet nothing really works... – Jaroslav Huss Jun 16 '22 at 19:24
  • @JaroslavHuss - Please post a new question with details. – John Hanley Jun 16 '22 at 20:48