Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

参考

ushio_s
go python php Unity Java javascript TypeScript CSS HTML ruby などなど
https://ushios.github.io/#!index.md
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした