いつもお世話になります。
centos6上でgoの環境を構築したいのですが、うまくいきません。ご教授をお願いします。
vagrant上にcentos6をインストールしています。
vagrant上でのIPアドレスは192.168.33.10です。
http://192.168.33.10でアクセスした際、Hello World!とですようにしたいです。
実行結果は、http://192.168.33.10の時、
http://192.168.33.10:9000の時、
http://192.168.33.10:9000でアクセスした時期待した結果になりました。
環境構築
$ brew install go $ brew install nginx
// .bashrc
# .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi export PATH=$PATH:/usr/local/nginx/sbin
ngnixの設定
// /etc/nginx/conf.d/default.conf
# # The default server # server { listen 81 default_server; listen [::]:81 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
// /etc/nginx/conf.d/golang.conf
server { listen 80; server_name localhost; location / { fastcgi_pass 192.168.33.10:9000; include fastcgi_params; } }
goの実行ファイル
// /var/golang/index.go
package main import ( "fmt" "net/http" ) type MyHandler struct{} func (h *MyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World!") } func main() { handler := MyHandler{} // handlerはハンドラ。 server := http.Server{ Addr: "192.168.33.10:9000", // Addr: ":9000", // これでもOK Handler: &handler, } server.ListenAndServe() }
ソースは環境構築のために簡単に書いたものです。centos6上にgoとngnixの環境を作成する目的は、https通信の環境を作るためです。
設定を以下のように変更しました。
しかし、うまくいきません。
error.logを見ると、接続できていないみたいです。
どのようにすれば、よろしいのでしょうか。
// default.conf
# # The default server # server { listen 81 default_server; listen [::]:81 default_server; server_name localhost; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
// golang.conf
server { listen 80 default_server; server_name 192.168.33.10; location / { fastcgi_pass 192.168.33.10:9000; include fastcgi_params; } }
/var/log/nginx/error.log
2017/10/22 05:28:15 [error] 15847#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.33.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.33.10" 2017/10/22 05:31:46 [error] 15934#0: *1 upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream, client: 192.168.33.1, server: 192.168.33.10, request: "GET / HTTP/1.1", upstream: "fastcgi://192.168.33.10:9000", host: "192.168.33.10" 2017/10/22 05:31:48 [error] 15934#0: *1 upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream, client: 192.168.33.1, server: 192.168.33.10, request: "GET / HTTP/1.1", upstream: "fastcgi://192.168.33.10:9000", host: "192.168.33.10"
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/22 04:40
2017/10/22 06:01 編集
2017/10/22 07:59
2017/10/22 08:30