英文:
Building and run go scripts on Apache under fcgi
问题
运行每个脚本的步骤如下:
go build script.go
mv script script.fcgi
我的Apache配置如下:
<VirtualHost [我的IP]: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)如果我构建一个脚本,它会将我链接的所有包都构建进去,对吗?
2)我如何自定义fcgi和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:
- If i build 1 script, it will builded with all packages that i link, right?
- How i can customize fcgi and go so that it will not need build every time
sorry for bad english
答案1
得分: 2
你无法直接在Apache中运行Go应用程序,因为Go不是一种“脚本语言”,Apache也不知道如何处理它(与PHP FCGI和其他变体不同)。
你需要使用一个HTTP或FCGI服务器来构建(编译)你的Go应用程序,并运行它,然后使用Apache(或nginx)来反向代理到你的Go应用程序监听的HTTP端口/FCGI套接字。
可以参考一下net/http文档和Go文档中的simple web application教程。根据我的经验,我建议使用反向HTTP代理而不是FCGI,因为它更容易调试和配置。
例如:
<VirtualHost myhost:80>
ServerName www.mydomain.com
ProxyPass / http://localhost:8000/ # 你的Go应用程序监听的端口
ProxyPassReverse / http://localhost:8000/
</VirtualHost>
请注意,这只是一个示例,没有经过测试,但希望能帮助你入门。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论