Setting Up The Server

The first thing to do when setting up a backend like that in which was used in this project.

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

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,

$ 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

Last updated