Golang在Apache上的CGI

huangapple go评论76阅读模式
英文:

Golang CGI on apache

问题

我正在尝试通过Apache运行Golang的CGI脚本。我可以编译文件,并且正在使用我找到的示例来创建它,但我不知道应该向Apache的"add handler"添加什么文件扩展名,或者是否应该告诉Apache处理Go编译源文件的位置。当前,当您在Web浏览器中访问cgi-bin文件时,只会下载Unix可执行文件。

如您所见,我尝试了.exe和.go这两个扩展名,但都没有按预期工作。

<Directory "/var/www/html/cgi">
    AddHandler cgi-script .cgi .py .exe .go
    AllowOverride All
    Options +Indexes +FollowSymLinks +ExecCGI
    Order allow,deny
    Allow from all
</Directory>

另外,cgi和cgi-script有区别吗?我一直在尝试两者,看哪个可以工作,但在当前的配置下都不起作用。

英文:

I am trying to run Golang cgi scripts through apache. I can get the files compiled and am using examples i found of how to make it, but I don't know what file extension to add to apache's "add handler" or if that is even where I should tell apache to handle the Go compiled source. Currently when you go to the cgi-bin file in a web browser you just download the Unix Executable File.
as you can see I have tried .exe and .go neither of which I expected to work, and didn't.

&lt;Directory &quot;/var/www/html/cgi&quot;&gt;
    AddHandler cgi-script .cgi .py .exe .go
    AllowOverride All
    Options +Indexes +FollowSymLinks +ExecCGI
    Order allow,deny
    Allow from all
&lt;/Directory&gt;

Also, does cgi vs cgi matter? I have been using both to see which ones work, but neither do with my current configuration.

答案1

得分: 1

有些服务器允许在cgi-bin之外执行cgi程序,而其他服务器则要求将其放在cgi-bin文件夹中。必须正确设置权限(例如755或其他权限)。

如果你决定在cgi-bin之外执行cgi程序,并且你的服务器允许这样做,这可能会带来安全问题。

在许多服务器上,你不需要为主要的cgi-bin文件夹添加处理程序,你只需要通过ftp或telnet设置文件权限。如果你下载文件而不是执行它,你确定使用ftp程序设置了正确的权限吗?尝试使用755、777和其他权限。

注意:Go程序不是脚本,它是一个编译后的可执行文件。对于二进制程序,你不需要解释器,因此你的服务器可能会对Go程序需要被解释为什么而感到困惑。你只需要以执行权限运行它,而不是将其解释为脚本。

如果你不遵循标准的cgi-bin文件夹设计,迁移服务器可能会成为一场噩梦。一些服务器由于安全或其他原因不允许所有的Apache配置修改,因此当你改变托管计划时,如果你使用非标准的配置修改,所有的程序和文件夹结构都可能会出现问题。

有些服务器甚至要求在jails中运行它们,这进一步复杂化了问题。弄清楚你的服务器是如何设置的,它允许什么,并研究执行所需的权限。

英文:

Some servers allow executing cgi programs outside of cgi-bin, other servers require them in cgi-bin folder. The permissions must be set correctly (i.e. 755 or other)

if you do decide to execute cgi programs outside of cgi-bin and your server allows it, this may be a security issue

On many servers you don't need to add handlers for the main cgi-bin folder, you just need to set file permissions by ftp or telnet. If you are downloading the file rather than executing it, are you sure permissions is set correct using an ftp program? Try 755, 777, and others

Note: a go program is not a script, it's a compiled executable. With a binary program, you don't need an interpreter so your server could be confused as to what a go program needs to be interpreted as. You just want to run it with exec permissions , not interpret it as a script.

Migrating servers can be a nightmare if you don't stick to standard cgi-bin folder design. Some servers don't allow all apache config modifications due to security or other concerns, so when you change hosting plans one day all your programs and folder structures could be broken if you use non standard config hacks.

Some servers even require them to be run in jails, which complicates matters further. Figure out how your server is setup and what it allows, and study what permissions are required to execute.

huangapple
  • 本文由 发表于 2015年4月4日 23:06:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/29447931.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定