douyasihefu6214 2014-03-01 03:12
浏览 30
已采纳

在fcgi下在Apache上构建和运行Go脚本

For run every script i do:

go build script.go
mv script script.fcgi

My apache config looks so:

<VirtualHost [myip]:80>
    ServerAdmin webmaster@example.com
    ServerName website.com
    DocumentRoot /home/user/www
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /our_bin [QSA,L]
    <Directory /home/user/www>
        Allow from all
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d [OR]
        RewriteCond %{REQUEST_URI} ^/$
        RewriteRule ^(.*)$ script.fcgi/$1 [QSA,L]
    </Directory>
</VirtualHost>

Question: 1) If i build 1 script, it will builded with all packages that i link, right? 2) How i can customize fcgi and go so that it will not need build every time

sorry for bad english

  • 写回答

1条回答 默认 最新

  • dowm41315 2014-03-01 05:53
    关注

    You can't. Go isn't a "scripting language" and Apache doesn't know how to process it (unlike PHP FCGI and variants).

    You need to build (compile) your Go application with a HTTP or FCGI server, and run it, and then use Apache (or nginx) to reverse proxy to the HTTP port/FCGI socket your Go app is listening on.

    Take a look at the net/http documentation and the simple web application tutorial in the Go documentation. From my experience I'd recommend using a reverse HTTP proxy over FCGI as it's easier to debug/configure.

    i.e.

    <VirtualHost myhost:80>
                    ServerName www.mydomain.com
                    ProxyPass / http://localhost:8000/ # Your Go app's listening port
                    ProxyPassReverse / http://localhost:8000/
    </VirtualHost>
    

    Note that this isn't tested nor a complete example, but should hopefully get you started.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教