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

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元