linux 下 编译 后台运行、开机启动 golang 程序
编译
go build test.go
指定输出文件
go build -o mygameserver
修改权限命令
chmod 777 程序名称
后台运行的命令
nohup ./程序名 &
不输出错误信息
nohup ./程序名 >/dev/null 2>&1 &
如果要关闭程序,可以使用命令”ps” 查看后台程序的pid,然后使用“kill 程序pid”命令,关闭程序比如程序名为test,可以用如下命令查询
ps aux|grep test
关掉进程
kill 进程编号
写进linux启动服务


注意网站配置路径不能用下划线_或-
[root@localhost ~]# chmod 777 /www/wwwroot/qncms/qn_web_api //设置执行文件权限
[root@localhost ~]# chmod 755 /etc/init.d/qncms //设置服务权限
[root@localhost ~]# chkconfig --add qncms //服务添加到服务列表
[root@localhost ~]# chkconfig --list //查询服务列表
[root@localhost ~]# chkconfig qncms on //开启服务
[root@localhost ~]# service qncms start //启动服务
[root@localhost ~]# nohup: appending output to 'nohup.out' //为正确执行
server {
listen 809;
server_name 114.116.20.225:809;
#charset koi8-r;
#access_log logs/host.access.log main;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:8001;
root html;
index index.html index.htm;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

浙公网安备 33010602011771号