前提
AWS EC2でGoを使用してみたく下記のhello.goを作成しました。
go
1// hello.go 2package main 3 4import ( 5 "fmt" 6 "log" 7 "net/http" 8) 9 10func helloHandler(w http.ResponseWriter, r *http.Request){ 11 fmt.Fprintf(w, "Hello World.") 12} 13 14func main(){ 15 http.HandleFunc("/test", helloHandler) 16 fmt.Println("webserver start.") 17 if err := http.ListenAndServe(":8080", nil); err != nil { 18 log.Fatal("error: ", err) 19 } 20} 21
ローカルで実行した際は http://localhost:8080/test にアクセスすれば、
Hello World、それ以外は404 Page Not Foundが表示されます。
わからないこと
EC2では、/var/www/go配下に 上記のhello.goを作成したのですが、
ipアドレスを1.123.45.67と仮定して
http://1.123.45.67:8080/testにアクセスしてもERR_CONNECTION_TIMED_OUTとなってしまいます。
何が問題なのか分からないので、教えていただきたいです。
その他
・goバージョン:1.9.4
・AMI:Amazon Linux2
・go run hello.go、もしくはbuildしたバイナリを実行した際に、func main2行目のwebserver start.はコンソールに表示されます。
・nginx等のwebサーバーは使用していません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/13 13:05