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.
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; } }
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.