douganggu4392 2017-10-28 09:35
浏览 127

从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 ?

  • 写回答

1条回答 默认 最新

  • duanhao7786 2017-10-28 10:30
    关注

    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 ...

    评论

报告相同问题?

悬赏问题

  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题