部署

gin部署
创建于:2021年03月01日

使用supervisor进程管理工具

supervisor

supervisor安装

创建项目配置文件 vim project.conf

[program:project-name]
command = nohup 项目绝对路径/main &
directory = 项目绝对路径
user =root
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true
stderr_logfile=/data/logs/error.log #错误日志文件必须存在

Nginx配置

server{

        listen 80;
        server_name xxx.com;

        rewrite ^ https://$http_host$request_uri? permanent;
}

server
    {
        listen 443 ssl;
        server_name xxx.com ;

        ssl_certificate  /usr/local/nginx/ssl/xxx.pem;
        ssl_certificate_key  /usr/local/nginx/ssl/xxx.key;


        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://127.0.0.1:8080; #转发到项目运行的端口
        }


        access_log off;
        error_log /data/logs/error-api.log;
    }