7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

golang製WAFのgojiでfastcgiを使ってnginxと連携する

Last updated at Posted at 2016-01-29

NGINXの設定

nginx.conf
server {
    listen       80;
    server_name  example.com;

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

この辺りはnginx + Go-FCGI で Web アプリを動かすの投稿を見ていただいて

終了時にUNIXソケットのファイルを削除するようにする

main.go
	listener, err := net.Listen("unix", "/var/tmp/go-fcgi.sock")
	if err != nil {
		return
	}

	// ここから
	sigc := make(chan os.Signal, 1)
	signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM)
	go func(c chan os.Signal) {
		// Wait for a SIGINT or SIGKILL:
		sig := <-c
		log.Printf("Caught signal %s: shutting down.", sig)
		// Stop listening (and unlink the socket if unix type):
		listener.Close()
		// And we're done:
		os.Exit(0)
	}(sigc)
	// ここをコピペする

	fcgi.Serve(listener, goji.DefaultMux)

備考

  • 不正に落ちた場合は削除されないので、起動時に削除したほうが良い?
  • deferとかで出来無いだろうか・・・

参考

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?