The language of Go, also known as Golang, is an open-source programming language developed by Google. Go is designed for efficiency, ease of use, and scalability. Go language is very popular for building web applications, microservices, and cloud -based applications. In this guide, we will discuss how to get a simple web application on Ubuntu using Nginx as Reverse Proxy and SystemD to manage application service.
Install Go
Update and install Go:
Sudo Apt Update Wget Sudo tar -c/usr/local -xzf go1.23.3.linux -amd64.tar.gz echo ‘export path = $ path:/usr/local/go/bin’ >> ~/. Profile Source ~/. Profile
|
sudo appropriate renew Wget https://go.dev/dl/go1.23.3.linux-amd64.tar.gz sudo ter –C /Usr/local –XZF Go1.23.3.linux–AMD64.ter.GZ echo ‘Path Export = $ path:/usr/local/go/bin’ >> ~/.profile source ~/.profile |
Verify the GO installation by displaying the version number:
The command response:
Go version Go1.23.3 Linux/AMD64
|
go version Go1.23.3 Linux/AMD64 |
Make a go app
Create a directory for application projects with names Goweb:
mkdir ~/goweb && cd ~/goweb
|
mkdir ~/Goweb && CD ~/Goweb |
Create a file Main.go:
Submit Main.go:
The main import package (“fmt” “net/http”) Func Handler (w http.responsewriter, r *http.request) {fmt.fprintf (W, “Hello, World!”)} Func Main () {http.handlefunc (“/”/”,” Handler) {http.handlefunc (“/”/”,” handler) {http.handlefunc (“”/”,” handler) HTT.
|
packaging main import ( “FMT” “NET/HTTP” ) Func Pawang(w http.Responsewriter, R *http.Request) { FMT.Fprintf(w, “Hello, the world!”) } Func main() { http.Handlefunc(“/”, Pawang) http.Listenandserve(“: 8080”, zero) } |
Application Compile:
Make service
Creating a service system system:
SUDO NANO/ETC/SYSYSTEMD/SYSYSTEM/GOWEB.Service
|
sudo Nano /etc./SystemD/system/Goweb.serve |
SUBMIT:
Description = Go Web App After = Network.Target
[Service]
Execstart =/Home/Youurizer/Goweb/App Restart = Always User = Youurizer Group = Youurizer Environment = Port = 8080
[Install]
WANTEDBY = MULTI-USER. TARGET
|
[Unit] Information=Go Web Application After=network.target [Service] Execstart=/House/Youurizer/Goweb/application Restart=always User=Youurizer Group=Youurizer Environment=HARBOR=8080 [Install] Searching for=multi–user.target |
Activate service:
Sudo SystemCTL Daemon-Reload Sudo Systemctl Activating Goweb Sudo SystemCtl Start Goweb Sudo SystemCtl Status Goweb
|
sudo SystemCTL Daemon–Re -load sudo SystemCTL possible Goweb sudo SystemCTL beginning Goweb sudo SystemCTL status Goweb |
Nginx configuration
Install Nginx:
sudo apt install nginx -y
|
sudo appropriate install Nginx –Y |
Creating Nginx Configuration Files:
SUDO NANO/ETC/NGINX/CONF.D/GOWEB.CONF
|
sudo Nano /etc./Nginx/conf.D/Goweb.conf |
SUBMIT:
server {listen 80; server_name yourdomain.com; location / {proxy_pass proxy_http_version 1.1; Proxy_Set_Header Upgrade $ http_upgrade; proxy_set_header connection ‘upgrade’; proxy_set_header host $ host; proxy_cache_bypass $ http_upgrade; }}
|
server { listen 80; server_name Your domain.com; Location / { Proxy_pass http:// localhost: 8080; proxy_http_version 1.1; proxy_set_header Increase $http_upgrade; proxy_set_header Connection ‘increase’; proxy_set_header Host $host; Proxy_cache_Bypass $http_upgrade; } } |
Restart nginx:
Sudo systemctl restart nginx
|
sudo SystemCTL Restart Nginx |
Application test
Open the browser and visit the address:
The result is the text “Hello, World!”.
Good luck 🙂
Game Center
Game News
Review Film
Rumus Matematika
Anime Batch
Berita Terkini
Berita Terkini
Berita Terkini
Berita Terkini
review anime
Comments are closed, but trackbacks and pingbacks are open.