How to post GO + Templ + HTMX + Tallwindcs to production
In this article, I will show you how to post Gotth (Go Templ HTMX Tailwind) for production.
I recently created my cryptocurrency exchange complex called Cyphergat; It finds the best price for your encryption exchange of different partnership exchanges.
She has two parts:
-
Application interface that interacts with stock exchanges. Written in Go and uses the jinn.
-
The web user interface is written in Go and uses a mixture of HTML, HTMX, Tailwindcs, CSS and Javascript in TEMPL templates. The nickname Gotth. It interacts with the application programming interface in order to find rates and etc.
What is very cool with this stack and preparation is that we are able to produce One With everything listed for each part and shipping it to the server. On the side of Webui, this is possible since HTML is assembled in the Go code using Templ and then charged with the two.
In this article, I will take my setting to facilitate you to make something like that.
Proven
I am using the DEBIAN Server 12, which will present my order through Cloudflare tunnels. All fixed files are presented via NGINX and API and web dualities are operated as Systemd services.
In this guide, I will show you how to prepare this.
preparation
I have one folder on my DeV device called Cyphergat: It contains:
api/
web/
builds/
The API folder includes the API source. The web includes the source source code.
The construction builds all the buildings that are published on the server.
Wind
The first real challenge comes with the preparation of Tailwindcss correctly.
In my web project, I have a fixed folder specifically for fixed files. Inside, I have two files:
/web
styles.css
tailwind.css
the styles.css
Simply contains:
@import "tailwindcss";
Tailwind.css file is the place where Tailwind-CLI will save its purposes.
To build Tailwind things, I simply run:
npx @tailwindcss/cli -i ./static/styles.css -o ./static/tailwind.css --watch
(Assuming that you installed Tailwind-CLI)
In the Header.temply file (the head of all pages), at the top I have:
Files are offered using Echo’s E.static (in my Main.go file).
func main(){
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Secure())
e.Static("/static", "static") // Serves content from static folder.
// Rest of the handlers
}
Server
On the side of my server, I have DEBIAN 12 VM runs on Proxmox.
In the home guide for users, I have a folder that contains the following content:
cyphergoat/
├── api
├── static/
└── web
Fixed folder has all fixed files (including tailwind.css and styles.css), and Web and API They are diodes.
After that I have two services for the organizer of these executives:
the cg-api.service
/etc/systemd/system/cg-api.service
[Unit]
Description=CypherGoat API
After=network.target
[Service]
User=arkal
Group=www-data
WorkingDirectory=/home/arkal/cyphergoat
ExecStart=/home/arkal/cyphergoat/api
Restart=always
RestartSec=1
[Install]
WantedBy=multi-user.target
and cg-web.service
/etc/systemd/system/cg-web.service
[Unit]
Description=CypherGoat Web
After=network.target
[Service]
User=arkal
Group=www-data
WorkingDirectory=/home/arkal/cyphergoat
ExecStart=/home/arkal/cyphergoat/web
[Install]
WantedBy=multi-user.target
Both are owned by the group www-data
(Perhaps this is not necessary for API) in order to facilitate their service via NGINX.
nginx
The website communicates with the application programming interface, but you still need to make Web-Ui available.
I have prepared Nginx with the following configuration: /etc/nginx/sites-available/cg
server {
server_name cyphergoat.com;
location / {
proxy_pass http://127.0.0.1:4200;
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;
}
location /static/ {
alias /var/www/static/;
expires 30d;
}
# Optional robots.txt
location = /robots.txt {
root /var/www/static;
access_log off;
log_not_found off;
}
listen 80;
}
I have also prepared CERTBOT for a SSL certificate.
You can set CERTBOT by running:
sudo apt install certbot python3-certbot-nginx -y
Create a SSL certificate:
sudo certbot --nginx -d cyphergoat.com
Read your Self Host Website to get a more deep NGINX setting.
Cloudflare tunnels
I am currently available access to my website using Cloudflare pages. It is a very easy -to -use solution.
To do this, you will need a Cloudflare account and a field indicates Cloudflare.
First, go to the Zero Trust dashboard.
under Networks
Click Tunnels,
And then Create a tunnel.
Once created, you must Install and run a connector
; Follow the guidelines mentioned on the page to prepare your specified.
After running the conductor, you must click Public Hostname
Tab and Add a public hostname
.
Now, you should see something like this:
Fill in information as I have. The type of service should be HTTP
And it must be the URL title 127.0.0.1:80
or localhost:80.
Obviously, there is no reason to make your application programming interface accessible to everyone when publishing your website.
Publishing
In order to publish my diodes, I moved forward and created a quick text:
cd api
go build -o ../builds/ .
cd ../web
templ generate && go build -o ../builds/web cmd/main.go
cd ..
rsync -urvP ./builds/ user@SERVER:/home/user/cyphergoat
rsync -urvP ./web/static user@SERVER:/home/user/cyphergoat/
rsync -urvP ./api/coins.json user@SERVER:/user/user/cyphergoat/
The text program will create an application programming interface, create Templ files, create Webui, then send everything to my server (including fixed folder).
After that SSH in my server:
ssh user@ip
Then restore the services.
sudo systemctl restart cg-api cg-web
This is all.
Related articles
The minimum minimum rate in Go (GIN)
How to build a brief URL in Go
How to post Django to production
© 2025 4RKAL CC BY-SA Subscribe