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.


Follow my new project: From Zero to App

A video-based learning project where I create a React + GraphQL app from idea to deployment! 9 free videos already out!