「CentOS7 / Nginx / CentOS7サービス経由で起動 / Go」 / 2018/4/29 → 2018/5/6

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


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 ~ ^/demo.*/(.*)\.go$ {
       fastcgi_pass  unix:/run/go/app/$1.sock;
       include       fastcgi_params;
   }
}


実行可能ファイルを生成


$ go build goweb.go

実行可能ファイルを配置


▼/opt/goweb

CentOS7サービス登録


Unit定義ファイルを作成
▼/etc/systemd/system/goweb.service
[Unit]
Description = go web start

[Service]
ExecStart = /opt/goweb
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target


CentOS7サービス設定


自動起動on
$ sudo systemctl enable goweb

起動
$ sudo systemctl start goweb