nginx通过代理使用80端口访问go web项目

server {
    listen       80;
    root /www/web/go;
    server_name go.hi-kai.top;

    location /nginx_status {
        stub_status on;
        access_log off;
    }

    location ~ /.well-known {
        allow all;
    }

    location ~ /\. {
        deny  all;
    }

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:8000/;
        proxy_set_header X-NginX-Proxy true;
    }
}

在linux中部署go web项目

把编译后的文件上传到服务器后,用下面的命令启动项目:

nohup ./gin > log.txt &

在启动命令最后加&,是后台启动,在前面加上nohup可以让服务在ssh断开后继续运行。

如果想停止服务,运行以下命令:

ps -ef | grep ./gin

通过用户名以及程序名等信息找到对应的 PID,使用 kill 命令强制终止进程(若PID为26928):

kill -s 9 26928