Reputation: 656
I came from a PHP background w/c is you can easily throw a PHP file in a server and that's it! How about in Golang, to be specific is the Beego framework because I already created a website using Beego but my stopper is (Q1)How to deploy in Ubunto and NGINX environment? (Q2)Do i need to compile the Beego project before deploying? (Q3)Do i need NGINX/Apache as server or use the built-in "run" of Beego?
Thank You.
Upvotes: 0
Views: 1545
Reputation: 387
How to deploy in Ubuntu and NGINX environment?
Create Nginx server block (https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04)
Example Server block pointing to Golang App running at localhost:9000:
server {
listen 80;
server_name my.domain.com;
location / {
proxy_pass http://localhost:9000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_pass_request_headers on;
proxy_read_timeout 150;
}
}
Upvotes: 1
Reputation: 1808
1 - Pretty much install golang (Using the built-in version: sudo apt-get install golang-go
or Detailed guide) and build the project or simply copy the built project and their libs if needed;
2 - Ideally, the production environment shouldn't include the source codes on most scenarios, therefore a built server could be better.
3 - Although not required, most people recommend to run golang behind a nginx. The reason for that is due to several optimizations (eg:static files serving) made on NGinx/Apache, which you would be missing on direct running your bin on server 80.
Side notes:
- the go run ...
is the same thing as the go build ...
+ run the built executable
- If you are just deploying the binary, build using the same OS / configurations.
- Remember to follow the basic security guides, just open the ports needed, secure the server before deploying, limit users access, etc.
Upvotes: 0