6
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

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

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とかで出来無いだろうか・・・

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
6
Help us understand the problem. What are the problem?