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 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算