Go, also known as Golang, is an open source programming language developed by Google. Go is designed for efficiency, ease of use, and scalability. Very popular for building web applications, microser services, and cloud -based applications. In this guide, we will discuss how to use a simple Go Web application on Ubuntu using Nginx as an inverted proxy and systemD to manage application services.
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:
Response to commands:
Go version Go1.23.3 Linux/AMD64
|
go version Go1.23.3 Linux/AMD64 |
Create a go application
Create a directory for the application project with a name Goweb:
mkdir ~/goweb && cd ~/goweb
|
mkdir ~/Goweb && CD ~/Goweb |
Create Main.go submit:
Fill in the file 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 Compilation:
Make services
Create SystemD Service File:
SUDO NANO/ETC/SYSYSTEMD/SYSYSTEM/GOWEB.Service
|
sudo Nano /etc./SystemD/system/Goweb.serve |
File:
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 Services:
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 |
Create Nginx Configuration Files:
SUDO NANO/ETC/NGINX/CONF.D/GOWEB.CONF
|
sudo Nano /etc./Nginx/conf.D/Goweb.conf |
File:
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 your browser and visit the address:
The result is the text “Hello, World!”.
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.