Use NGINX reverse proxy service Go service

One of the most common ways to show Go applications to the world is through a reverse proxy.

NGINX makes this very easy. This NGINX configuration can provide services for 2 different applications, listening on ports 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; } }

useproxy_set_header X-Real-IP $remote_addrMake sure you have the real address of the visitorhttp.Request.Header.Get("X-Real-IP")

Ports 8081 and 8082 can now be kept private, and NGINX provides services for them from a single entry point.

More tutorials: