Skip to content

API Gateway with Reverse Proxy and Upstream in NGINX

This document describes the configuration of a reverse proxy server using Nginx, designed to manage three different services: usermanagement, feedbackrequest, and feedbackresponse. Each service is associated with a specific URL on the main server, which listens on port 80.

Server Configuration

The configuration code defines three upstream blocks that specify the backend servers for each service:

  • usermanagement: user management server.
  • feedbackrequest: server for feedback requests.
  • feedbackresponse: server for feedback responses.

Each service is configured to run on port 8080.

Server Block

The main server listens on port 80 and has three locations defined, each forwarding requests to the respective backend service using proxy_pass.

Locations:

  • /users: Redirects to the usermanagement service.
  • /requests: Redirects to the feedbackrequest service.
  • /responses: Redirects to the feedbackresponse service.

The commented-out code snippets using rewrite are examples of how to rewrite URLs, but they are disabled in the current configuration.

Usage Examples

To access each service, you can make HTTP requests to the following URLs:

  1. For the user management service:

    GET http://<server>/users
    
  2. For the feedback request service:

    GET http://<server>/requests
    
  3. For the feedback response service:

    GET http://<server>/responses
    

Replace <server> with the IP address or hostname where Nginx is running.

Glossary

  • Nginx: A web server that can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache.
  • upstream: A configuration block in Nginx that defines a group of backend servers to which requests can be proxied.
  • proxy_pass: An Nginx directive that forwards requests to the backend servers specified in the upstream block.
  • rewrite: An Nginx directive used to rewrite URLs before forwarding the request to the backend.
  • Reverse Proxy: A type of server that retrieves resources on behalf of a client from one or more backend servers.