「CentOS7 / Nginx / コマンド起動 / Go」 / 2018/4/28

カテゴリー: 学習  閲覧数:327 配信日:2018-04-30 10:03


Nginx


▼/etc/nginx/conf.d/go-demo.w4c.work.conf
server {
   listen       80;
   server_name  go-demo.w4c.work;
   root   /var/www/◇◇/go-demo.w4c.work;
   #デフォルト 60秒を120秒までアップ
   fastcgi_read_timeout 120;  

   location / {
       fastcgi_pass  unix:/run/go/go-fcgi.sock;
       include       fastcgi_params;
   }
}


Go


下記ファイルは動作確認できたので、既に削除済
▼/var/www/◇◇/go-demo.w4c.work/index.go
package main

import (
    "os"
    "fmt"
    "net"
    "net/http"
    "net/http/fcgi"
)

func handler(res http.ResponseWriter, req *http.Request) {
    fmt.Fprint(res, "Hello World!")
}

func main() {
    os.RemoveAll("/run/go/go-fcgi.sock")
    l, err := net.Listen("unix", "/run/go/go-fcgi.sock")
    if err != nil {
        return
    }
    os.Chmod("/run/go/go-fcgi.sock", 0777)
    if err := os.Chown("/run/go/go-fcgi.sock", 994, 992); err != nil {//uid=994,gid=992
        fmt.Println("chown not permitted")
    }
    http.HandleFunc("/", handler)
    fcgi.Serve(l, nil)
}


コマンド起動


$ sudo go run index.go