LoginSignup
2
1

More than 5 years have passed since last update.

Go - Nginxを使った簡単な設定

Posted at

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 &
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1