从Nginx提供Golang脚本

I want to write a web application with go language.

When in run:

go run myscript.go

It works fine, i have worked with go "net/http" module Here is what i've done in my go script:

http.ListenAndServe(":8081", nil)

I want now to work with nginx. I have read i should put nginx in proxy mode. That means when nginx receive an http request on 80 http port, it will proxy it do 8081 port.

How can i automatically lanuch and relaunch "go run" process ?

In contrast to Php, Go isn’t a script run by a web server like Apache. It has another working model more close to php-fpm.

Go application is a standalone web server. It accepts connections and replies on a giver tcp port. It’s independent of nginx which can be installed on a separate machine. So it is supposed that app is running with external tools.

What problem do you want to solve with “launching Go app with nginx”?

UPD A Complete example:

  1. Install nginx on your server. Particular steps depend on your operation system. For Ubuntu it can be apt-get install nginx

  2. Edit nginx.conf to add proxy pass to pot 8081:

    location / {
        proxy_pass http://127.0.0.1:8081/;
    }
    
  3. Run you program go run ...