Go(beego)で作ったプログラムをNginxを使って動かす。
vim 8080ポートでgoのwebサーバを動かす(beegoの場合の設定例)
conf/app.conf
appname = hoge
httpport = 8080
runmode = prod
ビルドして実行する
$ go build
$ sudo nohup ./hoge &
Nginxの設定
hoge.conf
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
charset utf-8;
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;
}
}
再起動する場合
$ ps -aux | grep hoge
$ kill -9 12345
$ nohup ./hoge &