Deploying a Go service using Nginx

As we have already discussed, Nginx can be a reverse proxy for a Go application. Let's say that we have a server that provides a REST API to access book data. A client can send a request and get it back in JSON. The server also stores all the logs in an external file. Let's take a look at the steps to create this application:

  1. Let's name our project bookServer:
> mkdir -p $GOPATH/src/github.com/git-user/chapter12/bookServertouch $GOPATH/src/github.com/git-user/chapter12/bookServer/main.go

This file is a basic Go server to illustrate the functioning of a reverse proxy server. We first run our program on port 8000. Then, we add a configuration that maps 8000 (Go's running port) to 80 (the Nginx HTTP port). ...

Get Hands-On RESTful Web Services with Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.