ポートフォワーディング例 - tetsuyaf1100/hello-world GitHub Wiki

概要

社内ネットワークからEC2インスタンスにssh接続できるようになっている。
その他は、拒否されている。

EC2インスタンスにnginxを立ち上げて、社内ネットワークからブラウザで接続したい場合は、
ポートフォワーディングを利用する。

EC2インスタンスをたちあげて、nginx のコンテナを立ち上げる。
$ docker run --name hogehoge -d -p 8080:80 nginx
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
076e2487ef29        nginx               "nginx -g 'daemon of…"   16 minutes ago      Up 16 minutes       0.0.0.0:8080->80/tcp   hogehoge

[ec2-user@ip-10-0-11-107 docker-lessons]$ curl localhost:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
ポートフォワーディング

ローカルのポートをリモート先に転送

ssh -L 8080:localhost:8080 ec2-user@[ec2-instance ip address] -N  

-L local -N 待機状態

ブラウザで確認

http://localhost:8080/ にアクセス

⚠️ **GitHub.com Fallback** ⚠️