---
layout: storage
permalink: /:collection/:path.html
---
# Configure a hub on DigitalOcean
{:.no_toc}
This teaches you how to run a Gaia storage hub on DigitalOcean (DO). DigitalOcean is an affordable and convenient cloud computing provider. This example uses DigitalOcean Spaces for file storage. DigitalOcean Spaces is equivalent to AWS's S3 file storage solution.
DigitalOcean provides you with a compute machines known as a **Droplets** and storage called a **Spaces**. You need both to run a Gaia hub. The Gaia hub setup you create here, requires get a Digital Droplet with Docker pre-installed and a 250 GB Space. Each run for $5/month or a total of $10/month.
* TOC
{:toc}
Is this tutorial for you?
This documentation is appropriate for advanced power users who are familiar with command line tools, editing configuration files, and basic configuration of services of DNS or Nginx.
If you are planning on running an open-membership hub or an application-specific hub, you'll should see the section on Hub Operation
.
## Prerequisites you need
You use DigitalOcean choose and configure assets for running droplets and spaces. To enable this, you must be sure to complete a number of prerequisites.
### Required prerequisites on DigitalOcean
You must create an account on
Useful tips for the console
If you run into problems using the console, see the notes on this page in the DigitalOcean documentation.
If you find the output from ls difficult to read, try enter the following to change the console colors from the command line: LS_COLORS="di=1;31"
You can also edit your console .bashrc
. file permanently, of course.
## Task 4: Create a space key
1. In the DigitalOcean dashboard, go to the **API** page.
2. Scroll to the **Spaces Access Keys** section.
3. Click **Generate New Key**.
The system prompts you to give the key a name.
4. Enter a name for the key.
It is helpful to choose descriptive name like `gai-hub-key`.
5. Press the check mark.
The system creates your key and displays both the key and its secret.
![Access key](/storage/images/space-access-key.png)
6. Save your secrete in a secure password manager.
You should never share your secret.
7. Leave the page up with your key and secret and go to your open console.
## Task 5: Get the Gaia code and configure your server
You should have the console open as `root` on your Droplet. In this section, you get the Gaia code and configure the Gaia service.
1. Copy the Gaia code into your droplet using the `git clone` command.
```
root@moxiegirl:~# git clone https://github.com/blockstack/gaia.git
```
Successful output from this command looks like the following.
```
Cloning into 'gaia'...
remote: Enumerating objects: 63, done.
remote: Counting objects: 100% (63/63), done.
remote: Compressing objects: 100% (46/46), done.
remote: Total 4206 (delta 27), reused 35 (delta 17), pack-reused 4143
Receiving objects: 100% (4206/4206), 17.40 MiB | 9.89 MiB/s, done.
Resolving deltas: 100% (2700/2700), done.
root@moxiegirl:~#
```
This command creates a `gaia` subdirectory.
2. Change to `hub` directory in the `gaia` code.
```
cd gaia/hub
```
3. Copy the configuration sample to a new `config.json` file.
```
cp config.sample.json config.json
```
4. Edit your new `config.json` file with `vi` or `vim`.
```
vi config.json
```
You now need to edit this JSON file to have it store files on your DigitalOcean space.
5. Set the `driver` to `aws`.
The DigitalOcean space API exactly mimics the S3 API. Since Gaia doesn't have a DigitalOcean driver, you can just use the `aws` driver with some special configuration.
6. Set the `bucket` to the name of the DigitalOcean space you just created.
If your space is called `moxiegirl-hub-space`, the `bucket` value is `moxiegirl-hub-space`.
6. Set the `readURL` to the URL of the DigitalOcean space you just created.
If your space URL called `https://moxiegirl-hub-space.sfo2.digitaloceanspaces.com `, the `readURL` name is `https://moxiegirl-hub-space.sfo2.digitaloceanspaces.com`.
7. Add an `endpoint` value to the `awsCredentials` section.
```json
"awsCredentials": {
"accessKeyId": "",
"secretAccessKey": "",
"endpoint": ""
},
```
8. Go back to your DigitalOcean dashboard open to your space key.
9. Copy the **Key** and paste it into the `accessKeyId` value in the `config.json` file.
10. Copy the **Secret** and paste it into the `secretAccessKey` value in the `config.json` file.
11. In the DigitalOcean dashboard, choose the Spaces page.
12. Copy the section of your space URL that follows the name.
![Space endpoint](/storage/images/space-endpoint.png)
In this example, you would copy the `sfo2.digitaloceanspaces.com` section.
13. Paste the string you copied into the `endpoint` value.
14. Change the `proofsRequired` value to the number `0` (zero).
This will allow Blockstack user to write to your Gaia hub, without any social proofs required. You can change this later on, and do other things to lock-down this Gaia hub to just yourself, but that is outside the scope of this document.
At this point, the json.config file should be completed and appear similar to the following &emdash; but with your values.
```json
{
"servername": "",
"port": 3000,
"driver": "aws",
"bucket": "moxiegirl-hub-space",
"readURL": "https://moxiegirl-hub-space.sfo2.digitaloceanspaces.com",
"awsCredentials": {
"accessKeyId": "W7GBQGIUWDWKA6KAGL56",
"secretAccessKey": "O6hBYRPCeRmE0d9lr3Frtc345QsWt3l+mrDgvrVT9oE",
"endpoint": "sfo2.digitaloceanspaces.com "
},
"proofsConfig": {
"proofsRequired" : 0
},
"azCredentials": {
"accountName": "",
"accountKey": ""
},
"gcCredentials": {
"projectId": ""
},
"argsTransport": {
"level": "warn",
"handleExceptions": true,
"stringify": true,
"timestamp": true,
"colorize": false,
"json": true
}
}
```
15. Save and close the `vim` editor.
The system returns you back to the prompt.
## Task 6: Run the Gaia image with Docker
While your console is still in the the `gaia/hub` folder, build the `gaia.hub` image.
1. Enter the following `docker` command at the console command line.
```
docker build -t gaia.hub .
```
This build users the `Dockerfile` already in the `gaia/hub` folder. The output of the command is similar to the following:
```
....
npm WARN gaia-hub@2.3.4 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 877 packages from 540 contributors and audited 3671 packages in 38.122s
found 0 vulnerabilities
Removing intermediate container b0aef024879f
---> 5fd126019708
Step 5/5 : CMD ["npm", "run", "start"]
---> Running in ae459cc0865b
Removing intermediate container ae459cc0865b
---> b1ced6c39784
Successfully built b1ced6c39784
Successfully tagged gaia.hub:latest
```
2. Run your Gaia hub image.
```bash
docker run --restart=always -v ~/gaia/hub/config.json:/src/hub/config.json -p 3000:3000 -e CONFIG_PATH=/src/hub/config.json gaia.hub
```
This runs your Gaia hub on port `3000`. If everything runs successfully, the last line outputted from this command should be:
```bash
Successfully compiled 13 files with Babel.
{"level":"warn","message":"Listening on port 3000 in development mode","timestamp":"2019-01-23T16:35:05.216Z"}
```
3. If your command did run successfully, stop the service using the hotkey `ctrl-c`.
4. Run the the image again with this new command.
```
docker run --restart=always -v ~/gaia/hub/config.json:/src/hub/config.json -p 3000:3000 -e CONFIG_PATH=/src/hub/config.json -d gaia.hub
```
This command includes `-d` option to `docker run`. This runs Docker in detached mode, so that it runs in the background. You can run `docker ps` to see your running docker images, and get the `id` of your Gaia server.
```bash
root@moxiegirl:~/gaia/hub# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aeca7eea4a86 gaia.hub "npm run start" 11 seconds ago Up 10 seconds 0.0.0.0:3000->3000/tcp musing_payne
```
At this point, your Gaia service is up and running. You can run `docker logs MY_CONTAINER_ID` with your running image's ID to see the logs of this server at any time.
## Task 7: Set up an Nginx reverse proxy
In this task, you set up a simple Nginx reverse proxy to serve your Docker container through a public URL. You do this from the droplet console command line.
1. Install nginx into the droplet.
```
sudo apt-get install nginx
```
2. Enter `y` to confirm the installation.
3. Edit the nginx default configuration file.
```
vi /etc/nginx/sites-available/default
```
4. Inside the `location /` block (line 48), enter the following configuration:
```nginx
location / {
proxy_pass http://localhost:3000;
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;
}
```
This simple configuration passes all requests through to your Gaia hub running at port `3000`.
5. Save and close the file.
6. Run `nginx -t` to make sure you have no syntax errors.
```
root@moxiegirl:~/gaia/hub# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```
7. Restart `nginx` with your new configuration.
```
systemctl restart nginx
```
8. Allow access to your Gaia hub by exposing port 80 to the public.
```
ufw allow 80
```
## Task 8: Test your Gaia server
Now, you are ready to test your Gaia server and make sure it is up and running.
1. Click on **Droplets** in the sidebar.
2. Find your Droplet running Gaia.
![Droplet IP](/storage/images/space-endpoint.png)
3. Copy the IP address for it.
4. In your browser, visit the page `MY_DROPLET_IP/hub_info`.
You should see a response from your Gaia hub!
![Hub test](/storage/images/hub-running.png)
The `read_url_prefix` should be combine from the bucket and endpoint create
in your `config.json` file, for example,
`https://moxiegirl-hub-space.s3.amazonaws.com/`.
## Task 9: Configure a domain name
At this point, you can point a domain to your Gaia hub. Although it's not required, it is highly recommended. If you use a domain, you can migrate your Droplet to a different server (or even provider such as Azure or AWS) at any time, and still access it through the domain URL. Simply point your domain at the IP address for your Droplet. Use an `A Record` DNS type.
These instructions assume you have already created a free