Configure Digital Ocean for ssl (https) for free, (Bonus Meteor setup) — Video Series Part 5
In this section, we will configure Nginx and the meteor server to work together. This is Part 5in the entire video series — you can find the previous parts here.. Part 1, Part 2, Part 3 and Part 4.
Here is the video for part 5.
Step 1: Set up your custom domain
Go to your domain registrar and update your nameservers to point to
- ns1.digitalocean.com
- ns2.digitalocean.com
- ns3.digitalocean.com
This is what the iwantmyname settings look like:
Back on Digital Ocean add your domain name to your DNS records:
Now, create a new A record with the name of @ and your IP address like so:
Step 2: Ports and Redirects with nginx
let’s forward our domain to a different port number since nginx is listening on port 80. We’ll use port 3000. Create and edit a new file with:
sudo nano /etc/nginx/sites-available/default
Then past this block into that file:
server {
listen 80;
server_name game.coolmoviebites.com
# YOURDOMAIN.com;
access_log /var/log/nginx/app.dev.access.log;
error_log /var/log/nginx/app.dev.error.log;
location / {
proxy_pass http://XXX.XXX.XX.XXX:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Forwarded-For $remote_addr;
}}
Save and exit this file. Next, we’ll add a small security measure by hiding our nginx version number. Run,
sudo nano /etc/nginx/nginx.conf
Find and uncomment the line with
server_tokens off;
Save and exit this file. Then run:
sudo service nginx restart
To test the change, open a new terminal window and run:
curl -I http://www.yourdomain.com
In my case, it will be http://coolmoviebites.com
The top line should read “HTTP/1.1 301 Moved Permanently.”
When you try to access your page, you should get:
502 Bad Gateway
This means that the server is correctly redirecting to http://localhost:3000 (just like in our dev environments) but as we haven’t yet deployed our meteor app, we get a 502 html error.
Step 3: Using mupx to deploy your app.
Install Meteor Up
npm install -g mupx
Now, switch to your projects root directory and initialize mup.
cd ~/mup-your-project-name
mup init
This should create two files: mup.json and settings.json. Open mup.json and under the servers block, put in your details:
// Server authentication info
"servers": [
{
// the domain linked to Digital Ocean
"host": "coolmoviebites.com",
// the new user you created on the server
"username": "abhay",
// the SSH key you generated earlier
"pem": "~/.ssh/id_rsa"
}
],
Then, a bit further down in the same file:
// Application name (No spaces)
"appName": "coolmoviebites", //you need to put in your app's name.// Location of app (local directory)
"app": ".", // "/path/to/the/app"// Configure environment
"env": {
"ROOT_URL": "https://coolmoviebites.com",
// any port other than 80 (the default)
// because nginx is running on port 80
"PORT": 3000
},
Now, within your ~/mup-your-project-name directory, setup your server by running
mupx setup
Then deploy your app with:
mupx deploy
If successful, your output should look like:
Visit your domain
That should do it. Your site should be live.
Once again, Thank you so much for sticking along. Just keep spreading the word for https://coolmoviebites.com to your friends and their friends.