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:
- Let's name our project bookServer:
> mkdir -p $GOPATH/src/github.com/git-user/chapter12/bookServer
touch $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).
- Now, let's write the code. We will use a few packages for our server. We can use Go's built-in net/http package...