Skip to content

Instantly share code, notes, and snippets.

@junftnt
Forked from atomaths/nginx.conf
Created September 22, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junftnt/da3024194ef414a16460d9c33515a921 to your computer and use it in GitHub Desktop.
Save junftnt/da3024194ef414a16460d9c33515a921 to your computer and use it in GitHub Desktop.
This is a FastCGI example server in Go.
## FastCGI
server {
location ~ /app.* {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
## Reverse Proxy (이 방식으로 하면 http.ListenAndServe로 해야함)
server {
listen 80;
# listen 443 ssl;
server_name api.golang.org;
location ~ / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:3000;
}
}
package main
import (
"fmt"
"net/http"
"net/http/fcgi"
"net"
)
type FastCGIServer struct{}
func (s FastCGIServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("This is a FastCGI example server.\n"))
}
func main() {
fmt.Println("Starting server...")
l, _ := net.Listen("tcp", "127.0.0.1:9000")
b := new(FastCGIServer)
fcgi.Serve(l, b)
}
// 아래처럼 HandleFunc를 등록해서도 처리가능
func main() {
http.HandleFunc("/foo", fooHandler)
l, err := net.Listen("tcp", "127.0.0.1:9000")
if err != nil {
panic(err)
}
fcgi.Serve(l, nil)
}
func fooHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment