One of the most common ways to expose a Go application to the world is through a reverse proxy.

NGINX makes this very easy. This NGINX configuration serves 2 different applications listening on port 8001 and 8002 respectively.

server {
   listen 80 default_server;
   server_name your-domain;

   location /go-service-1 {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://localhost:8001;

   location /go-service-2 {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://localhost:8002;

Using proxy_set_header X-Real-IP $remote_addr ensures that you’ll have the visitor’s real address in http.Request.Header.Get("X-Real-IP")

The 8081 and 8082 ports can now stay private, and NGINX serves them from a single point of entry.

Did you know?

I have 7 premium training programs that will transform you, quickly, into an excellent Node/React/JS/Vue/Next.js/Svelte developer. Choose your own adventure. Practical lessons to learn the 80% of the things that you need to know, in 20% of the time!

⬇️ ⬇️ ⬇️

Check out all my courses now!

⬆️ ⬆️ ⬆️