前回,Conoha Wing にGolangを入れてbuild環境を作る. - じゃあ、おうちで学べるでbuild環境を準備した. 次はやっぱり,FCGIで動かしたいよな~
やってみる
この世の中には便利なものがある golang-apache-fastcgi/examples/vanilla at master · bsingr/golang-apache-fastcgi · GitHub の通りに設置してみる.
~/public_html/<domain_name>/.htaccess
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
</IfModule>
Options +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteRule ^(.*)$ hello_world.fcgi/$1 [QSA,L]
~/public_html/<domain_name>/hello_world.go
package main
import (
"fmt"
"io"
"log"
"net/http"
"net/http/fcgi"
"os"
"runtime"
)
var app_addr string
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
app_addr = os.Getenv("APP_ADDR") // e.g. "0.0.0.0:8080" or ""
}
func ServeHTTP(w http.ResponseWriter, r *http.Request) {
headers := w.Header()
headers.Add("Content-Type", "text/html")
io.WriteString(w, "<html><head></head><body><p>Hello world from Go!</p><table>")
io.WriteString(w, fmt.Sprintf("<tr><td>Method</td><td>%s</td></tr>", r.Method))
io.WriteString(w, fmt.Sprintf("<tr><td>URL</td><td>%s</td></tr>", r.URL))
io.WriteString(w, fmt.Sprintf("<tr><td>URL.Path</td><td>%s</td></tr>", r.URL.Path))
io.WriteString(w, fmt.Sprintf("<tr><td>Proto</td><td>%s</td></tr>", r.Proto))
io.WriteString(w, fmt.Sprintf("<tr><td>Host</td><td>%s</td></tr>", r.Host))
io.WriteString(w, fmt.Sprintf("<tr><td>RemoteAddr</td><td>%s</td></tr>", r.RemoteAddr))
io.WriteString(w, fmt.Sprintf("<tr><td>RequestURI</td><td>%s</td></tr>", r.RequestURI))
io.WriteString(w, fmt.Sprintf("<tr><td>Header</td><td>%s</td></tr>", r.Header))
io.WriteString(w, fmt.Sprintf("<tr><td>Body</td><td>%s</td></tr>", r.Body))
io.WriteString(w, "</table></body></html>")
}
func main() {
http.HandleFunc("/", ServeHTTP)
var err error
if app_addr != "" { // Run as a local web server
err = http.ListenAndServe(app_addr, nil)
} else { // Run as FCGI via standard I/O
err = fcgi.Serve(nil, nil)
}
if err != nil {
log.Fatal(err)
}
}
~/public_html/<domain_name>/Makefile
SCRIPT=hello_world
pack:
go build ${SCRIPT}.go
unpack:
mv ${SCRIPT} ${SCRIPT}.fcgi
Make
make pack make unpack
とりあえず,アクセス
できん
従来のFastCGIより20%も速くPHPアプリケーション実行できる実行環境「LiteSpeed LSAPI」を採用しています。
ほう
高速化の為にFastCGIを捨ててLiteSpeed LSAPIを採用しているからFastCGIが動かんのか!!!!!!!!
参照
第4のWebサーバー LiteSpeedとは - ts0818のブログ Poll : What is the most powerful and fastest web server? | Web Hosting Talk
意地でも動かしたい... 知見が欲しいです.
プログラムをphpから呼びだして実行するなんてのは悔しい. OSSでもGolangで動かそうみたいな動きはない.,...
うぅうううう