Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What is going on with this article?
@ushio_s

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

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

参考

6
Help us understand the problem. What is going on with this article?
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
ushio_s
go python php Unity Java javascript TypeScript CSS HTML ruby などなど

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
6
Help us understand the problem. What is going on with this article?