In ssh port forwarding, when forwarding to local, I want to forward it to the specified path in local.

Asked 1 years ago, Updated 1 years ago, 83 views

Looking at this page, I understand about ssh port forwarding roughly.

http://komaken.me/blog/2014/05/23/ssh-remote-forward%E3%82%92%E5%88%A9%E7%94%A8%E3%81%97%E3%81%A6%E5%A4%96%E9%83%A8%E3%82%B5%E3%83%BC%E3%83%90%E3%81%AE%E3%83%AA%E3%82%AF%E3%82%A8%E3%82%B9%E3%83%88%E3%82%92%E3%83%AD%E3%83%BC%E3%82%AB/

When accessing an EC2 instance with a global address (example.com:9876),
I would like to transfer to the server (localhost:80) that is starting with local.

 *Because I don't actually have a domain yet
This is the public DNS that can be used when creating EC2.
ec2-<IP address>.ap-northeast-1.compute.amazonaws.com

However, I would like you to forward it to the URL of localhost/sample/hoge when you receive a GET request for the URL example.com/sample/hoge.

ssh-R80:example.com:9876 [email protected]

Based on these, there are two things I don't understand.

1) After ssh with the above command and curl, port9876: connection denied is displayed.
In addition, the EC2 security group is open to the public.

curl example.com:9876-X GET

Custom TCP Rules (Type)
TCP (Protocol)
9876 (port)
0.0.0.0/0 (source)

2) Also, in question 1, we did not specify a path, but we do not know how to transfer it to the path specified in local above.

Thank you for your cooperation.

ssh

2022-09-30 19:28

1 Answers

As mentioned in the comment, ssh-R9876:localhost:80 [email protected] is the correct command.Access to example.com:9879 is now forwarded to port 80 on the PC running ssh.
For more information, see this article.
Also, I think you should write GatewayPorts yes on the server (EC2 instance) sshd_config (/etc/ssh/sshd_config) on example.com.Be careful not to mistake it for ssh_config.

There is nothing to do about (2), because ssh is talking about the transport layer, and the path of the HTTP request is data from the layer above it, so it should be transferred as it is.


2022-09-30 19:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.