一、进入到本地项目,而后执行命令linux
bee pack -be GOOS=linux
二、把生成的压缩文件上传到服务器,解压。nginx
一、编辑nginx.conf文件后端
二、添加以下配置服务器
server { listen 8081; server_name _; charset utf-8; access_log /data/wwwlogs/access_go.log combined; location / { try_files /_not_exists_ @backend; } location @backend { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; proxy_pass http://localhost:8080; } }
意思是:监听8081端口的请求,而后反向代理到 http://localhost:8080。也能够配置域名,能够都是80的端口,经过不一样的域名进行反向代理到不一样的go项目。tcp
三、阿里云和服务器防火墙开放端口阿里云
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 8081 -j ACCEPT && service iptables save
四、后台运行命令spa
nohup ./beepkg &
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT && service iptables save
由于go项目配置的8080端口,因此直接开放8080端口便可。代理
nohup
命令,把应用部署在后端,以下所示:nohup ./beepkg &
这样你的应用就跑在了 Linux 系统的守护进程code