apache - 在 fcgi 下在 Apache 上构建和运行 go 脚本

标签 apache go fastcgi

运行我做的每个脚本:

go build script.go
mv script script.fcgi

我的 apache 配置看起来是这样的:

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

问题: 1) 如果我构建 1 个脚本,它将与我链接的所有包一起构建,对吗? 2) 我如何自定义 fcgi 并运行,这样它就不需要每次都构建

对不起英语不好

最佳答案

你不能。 Go 不是一种“脚本语言”,Apache 不知道如何处理它(与 PHP FCGI 和变体不同)。

您需要使用 HTTP 或 FCGI 服务器构建(编译)您的 Go 应用程序并运行它,然后使用 Apache(或 nginx)反向代理到您的 Go 应用程序正在监听的 HTTP 端口/FCGI 套接字。

看看 net/http文档和 simple web application Go 文档中的教程。根据我的经验,我建议在 FCGI 上使用反向 HTTP 代理,因为它更容易调试/配置。

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

请注意,这没有经过测试,也不是一个完整的示例,但希望能帮助您入门。

关于apache - 在 fcgi 下在 Apache 上构建和运行 go 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22109629/

相关文章:

PHP mysqli() 不工作

apache - 如何使用 Apache 将 Go 应用程序与 MediaWiki 一起部署?

apache - piwik 跟踪器状态 500 安装错误

docker - 在 helm 安装之前将 go 二进制文件移动到 pod 中的惯用方法是什么?

php - 如何为持久性 PHP FastCGI 进程设计应用程序?

c++ - C/C++ 中的 CGI/FastCGI 应用程序(套接字编程问题)

apache - 有名为 'apache2' 的进程正在运行

math - 一种具有快速能力的原型(prototype)语言

regex - 用于将键值对解析为字符串映射的 Golang 正则表达式

Perl CGI 与 FastCGI