> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/~/changes/xKUM0sBXFkyR8F24yAMq/deployment/base-infrastructure/load-balancer/nginx.md).

# Nginx

Installation of Nginx load balancer

Nginx is used as both reverse proxy and load balancing for on-prem deployments.

## Installation

* Run this to install nginx;

  ```bash
  sudo apt install nginx
  ```
* Run this to delete default server;

  ```bash
  sudo rm /etc/nginx/sites-enabled/default
  ```
* Restart nginx

  ```bash
  sudo systemctl restart nginx
  ```

This is only a one-time installation. Whenever you want to add new servers to this Nginx, follow [Install Servers to Nginx Section](#install-servers-to-nginx).

## Install Servers to Nginx

This section applies only to one Server. Repeat this section for every server to be added.

### Pre-requisites

* [Create wildcard TLS certificates](/~/changes/xKUM0sBXFkyR8F24yAMq/deployment/deployment-guide/ssl-certificates-using-letsencrypt.md) (required to terminate HTTPS connects at Nginx)

### Installation

(TODO: Change this section; add a choice between `stream` & `http`.)

* Navigate to `/etc/nginx/sites-available` directory and create a file called `<sandbox name>.conf` (Example: `prod-openg2p.conf`) by using [kubernetes/nginx/server.sample.conf](https://github.com/OpenG2P/openg2p-deployment/blob/main/kubernetes/nginx/server.sample.conf) file as a template.
  * Use a new Listen IP Address for every server. It is recommended to add a new Network Interface in the same VM which is part of the same network.
  * When configuring upstream servers, the node port of Istio Ingressgateway will need to be configured. So it is important to understand the ports and figure out which ports connect to which Ingressgateway and for what purpose.
* Run this to enable the server that is just added.

  ```bash
  sudo ln -s /etc/nginx/sites-available/<sandbox name>.conf /etc/nginx/sites-enabled/
  ```
* Test nginx conf for errors:

  ```bash
  sudo nginx -t
  ```
* Restart nginx

  ```bash
  sudo systemctl restart nginx
  ```

### Post-installation

Map the hostnames to Nginx IPs on your DNS service (Map the hostnames to Nginx IPs on your DNS service (Route53 on AWS)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openg2p.org/~/changes/xKUM0sBXFkyR8F24yAMq/deployment/base-infrastructure/load-balancer/nginx.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
