# Setting Up The Server

For EggChat, the backend was hosted on an EC2 AWS instance. The server ran Ubuntu. Use the AWS control panel to provision an instance. Then download the key-pair associated with the instance to ssh into the server

{% hint style="info" %}
&#x20;Make sure that you create any necessary security group rules to allow tcp, http, https, and ssh ports into and out of the server. You may also need an internet gateway,  &#x20;
{% endhint %}

```
$ ssh -i "path_to_key" user@ip_address_or_url
```

Once you access the server you should download the necessary files and libraries to allow your code to run on the server.

You'll need: Docker, Docker-compose, and NGINX

```
$ sudo apt-get update
$ sudo apt-get install docker.io
$ sudo apt-get install nginx
$ sudo apt-get install docker-compose
```

Now navigate to /etc/nginx/conf.d and create a nginx configuration file

```
$ sudo nano reverse_proxy.conf
```

Then paste the following code in:

```
server {
        listen 80;
        listen [::]:80;

        server_name url_of_server;
        access_log /var/log/nginx/reverse-access.log;
        error_log /var/log/nginx/reverse-error.log;
        proxy_set_header Host   $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
                 proxy_pass http://internal_ip:8080/;
                 proxy_http_version 1.1;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection 'upgrade';
                 proxy_set_header Host $host;
                 proxy_cache_bypass $http_upgrade;

        }
}

```

Then to restart the nginx server, run the following command

```
$ sudo systemctl restart nginx
```

Now we can set up the docker components of the server

Wherever you want (but I recommend in the user folder) create a file named docker-compose.yml using the following command

```
$ sudo nano docker-compose.yml
```

and paste the following code in:

```
version: "2"
services:
  app:
    restart: always
    image: guydw/eggchatbackend:latest
    ports:
      - "8080:8080"
    links:
      - mongo
    expose:
      - "5000"
  mongo:
    container_name: mongo
    image: mongo
    ports:
      - "27017"

```

To run the server, run this and follow any prompts it gives:

```
$ sudo docker-compose up
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guydwilks.gitbook.io/avanced-animation/setting-up-the-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
