Zhonghui

每个不曾起舞的日子,都是对生命的辜负

User Tools

Site Tools


程序:go:自行分发代码

自行分发Go代码

2025/07/01 踩了好几次坑,还是没有解决这个问题,决定之后再看


踩坑经验1:静态Apache 2

使用Apache 2配置一个静态的HTTPS网站,然后把Go需要的<mate>写在index.html里面,结果Apache 2处理斜线有问题。

对于每个仓库,我们来创建html文件,假设静态网页映射的根目录是/var/www/html_go(注意这个目录最好还是属于www-data:www-data),那么我们在这个目录下创建:repo_name/index.html(比如/var/www/html_go/zh_math/index.html)

<html>
  <head>
    <meta name="go-import" content="go.osakayaki.com/zh_math git https://go.osakayaki.com/git/zh_math.git">
  </head>
  <body>OK</body>
</html>

git仓库使用Apache 2配置别名进行分发

失败

踩坑经验2:手写go-import

首先,配置DNS记录,然后配置acme.sh,申请证书,创建一个空白的HTTPS网站(Apache 2,反向代理,参照Apache 反向代理,注意使用nocanon,不要让Apache 2修改path),确保可以访问

在服务器上创建git仓库,建议放在/var/git,可以用sudo在/var创建一个git/然后把所有权转给自己。注意这个git/要把others的rx权限打开,Apache 2要读取(是的,虽然我们使用了反向代理,但是静态资源还是交给Apache 2分发)。在/var/git下面创建git仓库,这里我们演示创建两个,参照自己搭建Git服务器,确保可以clone,然后创建一些代码(go mod init go.osakayaki.com/zh_math)push上去,这里我们先不管版本控制的问题

在Apache 2的配置文件中配置别名,需要让Apache 2知道:go.osakayaki.com/git 是对应的哪个文件夹,并且这个path不进行反向代理。

ProxyPassMatch ^/git/ !
Alias /git/ /var/git/
<Directory /var/git/>
    Options +Indexes
    Require all granted
</Directory>

ProxyPassMatch ^/icons/ !
Alias /icons/ /usr/share/apache2/icons/
<Directory "/usr/share/apache2/icons">
    Options Indexes MultiViews
    AllowOverride None
    Require all granted
</Directory>

现在在浏览器中请求:https://go.osakayaki.com/git/zh_math.git,应该已经可以看见资源了(裸仓库)

启动Go的后端,处理请求,https://github.com/GZhonghui/go-import

403/404/500 的各种错误都有,放弃了,Apache 2不适合(我也太菜了)

失败

athens

Misc

/var/www/DokuWikiStick/dokuwiki/data/pages/程序/go/自行分发代码.txt · Last modified: 2025/07/01 06:24 by zhonghui