M
M
Michail Wowtschuk2017-03-04 20:54:27
Nginx
Michail Wowtschuk, 2017-03-04 20:54:27

Nginx not working with GO over socket?

Nginx does not work with GO via socket, what could be the reason?

//GO
package main

import (
  "fmt"
  "net"
  "net/http"
  "net/http/fcgi"
)

func handler(res http.ResponseWriter, req *http.Request) {
  fmt.Fprint(res, "Hello World!")
}

func main() {
  // For local machine
  l, err := net.Listen("unix", "/var/run/go-fcgi.sock")

  
  if err != nil {
    return
  }
  http.HandleFunc("/", handler)
  fcgi.Serve(l, nil)
}


//Nginx
server {
    listen 122.20.34.85:80;
    server_name mysite.com;

    access_log off;
    error_log /dev/null crit;

    location / {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/go-fcgi.sock;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Sergeevich, 2017-03-09
@gosolivs

At the end of the Main function write http.ListenAndServe(":8080", nil) and listen to localhost on port 8080

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question