I’ve been asked for a walkthrough of how to install iFramely for use with NodeBB several times, and figured it was about time I posted a guide I’ve assisted @cagatay and @DownPW with their installations, but this should be useful for anyone else looking to do something similar.
By way of background, the “hosted” version of iFramely works extremely well, but is not free (what is?) and you’ll exceed their API limit for the free plan very quickly - at which point, they’ll email and inform you that you need to upgrade to one of their paid plans.
Sadly, these aren’t cheap, however, iFramely do very kindly provide a self-hosted version of their application, and you can find out how to install that here. This guide assumes you have a fully functional copy of NodeBB running, and have already installed and activated the relevant plugin. If you haven’t installed the plugin, do this now (from CLI as it’s not listed in the GUI)
npm install nodebb-plugin-iframely
Now activate the plugin, but don’t configure it for the moment. You’ll need to rebuild and restart NodeBB also - don’t forget this step.
Whilst it’s perfectly “feasible” to install iFramely in the same domain as where you host your NodeBB instance, this isn’t generally recommended for security reasons. It ideally needs to be installed in a sub domain (or dedicated domain if you have one), so if your NodeBB URL is something like https://mynodebb.com
then the subdomain would be something like https://media.mynodebb.com
I’m detecting some head scratching already - how to I create a subdomain, yes? Well, it differs quite heavily depending on the platform you are using, but for sake of keeping this guide short, I won’t list every single method - that would take forever! Instead, let’s take the most common and effective route - Cloudflare.
Configure DNS for subdomain
- Login to the Cloudflare dashboard for your domain, and select DNS
- Add a new A record called “media” and have this point to the same IP address as your existing site
- Ensure that the proxy is enabled (orange cloud - grey cloud is DNS only) so that we pass the same wildcard cert to your server as the existing NodeBB site does
- DNS convergence on Cloudflare is typically within 60 seconds, so it’ll populate very quickly
- If you really want to see how far the propagation has advanced, use this site (very easy to use and self explanatory)
https://www.whatsmydns.net/
Configure NGINX to accept traffic for new subdomain
You now need to configure your NGINX
installation so that it will accept the subdomain when traffic is sent towards it - leaving this step out means your server will likely discard the traffic and you’ll land up with a 404 error
Depending on your *nix build, the nginx.conf
file may be in different places. If you know where your specific conf file is for your NodeBB install, open that now.
- You’re going to add the below config (note that some parts such as certificate paths need to be changed so they match the same ones you’re using for NodeBB)
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/key.pem;
ssl_client_certificate /etc/ssl/cloudflare.crt;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
server_name media.mynodebb.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:8061/;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Again, this is just an example, and will likely need to be modified. Essentially, what we are doing here is sending all traffic into a reverse proxy, where the iFramely installation is listening on port 8061, but will only answer requests from localhost
. This makes the installation much more secure as the reverse proxy is responsible for directing the traffic, and also means you can use https://media.mynodebb.com
instead of having to use https://media.mynodebb.com:8061
which incidentally, if you are using Cloudflare, this particular port isn’t routable with the free plan, so something to be aware of
Obviously, don’t forget to change https://media.mynodebb.com
with your actual URL
- Save and close the
nginx.conf
file
- Test the config by running
nginx -t
in the CLI (this validates the config before restarting the service to prevent issues)
- If all ok in step 3, restart the NGINX service - note that command will vary depending on the Linux distribution you are using, but generally
sudo service nginx restart
should work in most cases (if you are using a Debian backed build)
Install iFramely
- At the root of your
home
(again, this depends on where you’ve installed NodeBB - easy to determine as it will contain the NodeBB installation directory when navigated to) issue the following CLI
mkdir iframely
git clone https://github.com/itteco/iframely.git
cd iframely
npm install
Note that the user you are installing iFramely under needs admin rights - in most cases, you can use sudo npm install
if the first attempt fails. If the user is not in the sudoers
file, then you should use su root
and then provide the password. Then complete the install
- Once the installation is complete, there are some more steps
cp config.local.js.SAMPLE config.local.js
nano config.local.js
The above copies the “sample” config file and creates a new file called config.local.js
. I’m also using nano
as the text editor, as I can’t stand vi
I’ll leave that preference up to you…
- With the editor open, locate the
baseAppUrl
variable and place the actual URL of the subdomain you are going to use
baseAppUrl: "https://media.mynodebb.com", // use "https://yourdomain.com/path" where you have Iframely in your reverse proxy
- Save and exit the file
Start an iFramely instance
- Type
node server
into the CLI and press enter
- This will start a single instance of iFramely
- Now navigate to
admin/plugins/iframely
in your NodeBB installation
- Enter the URL you are going to be using as below
Make sure that the URL is appended with /iframely
as this is the API endpoint where requests are sent
- Save the settings
- Reload NodeBB
Initial testing
- Create a new post and place a URL inside it such as https://www.whatsmydns.net/ inside it
- Add tags if needed
- Post it
Hopefully, it’ll look something like this
In addition, if you switch back to the server CLI, you should see items being logged. At this point, it works but you’re not quite finished
Using PM2 to create a spawned process daemon
- Go to the CLI on your server and stop the running
node server
by using CTRL + Z
- Ensure that you are in the same folder as the iFramely installation
npm install pm2 -g
pm2 start pm2.json
pm2 logs
Again, make sure that the account you are using has root permissions when try to use npm install
as previously mentioned
You should hopefully see a log being generated like the below which is updated in real time when accessing posts with links
You can safely exit the log with CTRL + C
which won’t affect the daemon.
If you want to see if the process is running or not, you can use pm2 status
Similarly, if you need to restart the instance, you can do so using
pm2 reload iframely
That’s pretty much it - hope this was useful.