Golang Mux Webapp Project Skeleton
- Build for linux (Ubuntu) architecture amd64:
cd <PROJECT>/
env GOOS=linux GOARCH=amd64 go build -o webapp -v
- Copy your project excluding the Go source
*.go
to your server in /var/www/html/<PROJECT>
.
- Configure supervisor to run the app.
sudo vim /etc/supervisor/conf.d/<PROJECT>.conf
# add the following
[program:<PROJECT>webapp]
environment =
ENV=prod,
command=/var/www/html/<PROJECT>/webapp
autostart=true
autorestart=true
startretries=10
user=www-data
directory=/var/www/html/<PROJECT>/
redirect_stderr=true
stdout_logfile=/var/log/supervisor/<PROJECT>webapp.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
# reload supervisor
sudo supervisorctl reload
- Configure nginx as the frontend.
sudo vim /etc/nginx/sites-available/<PROJECT>.conf
# add the following
upstream <PROJECT> {
server unix:/tmp/<PROJECT>.sock;
}
server {
listen 80;
server_name <PROJECT>;
access_log /var/log/nginx/<PROJECT>-access.log;
error_log /var/log/nginx/<PROJECT>-error.log error;
location /static/ { alias /var/www/html/<PROJECT>/res/assets/; }
location / {
proxy_pass http://<PROJECT>;
}
}
# enable the website configuration
sudo ln -s /etc/nginx/sites-available/<PROJECT>.conf /etc/nginx/sites-enabled
sudo service nginx reload