1、编译go项目为可执行文件,如main文件
go build main.go
编译不同环境mac、linux、windows请参考:go build 编译成不同环境的可执行文件mac、linux、windows
2、上传文件到服务器(linux为例子),请给予执行权限775

3、执行main文件(具体端口由自己代码固定)
./main #nohup ./main & #后台运行,关闭终端不影响 #nohup ./main &>> log.txt & #把输出日志放到log.txt里面

4、可以通过ip:端口访问了(前提的你开启了端口权限!!!)

5、通过nginx代理访问
修改nginx的配置
server
{
listen 807;#外网访问端口,默认80
server_name go.test.top;#自己的域名
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/go.test.top;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#代理转发到go
proxy_pass http://localhost:8855;
}
#省略其它
}
6、重启nginx(不会就重启服务器吧)
systemctl start nginx
7、正常访问代理的go.test.top:807

8、到这里还不行就跟我搬砖吧