My Profile Photo

Personal Webpage of David Duggins


Well, I was born on a normal day in July, 1981 and have been creating chaos ever since. Born in North Carolina, but raised in the aftermath of the Soviet Union, Kazakhstan, I have been messing around with computers nearly my entire life. I wrote my first program in assembly when I was 11. In my early teens I ran a BBS connected to Fidonet and started building a website for my band. In 1999 I was introduced to Linux, and it was love at first compile. I started my career in IT in the early 2000's doing IT for a Car Dealership in Charlotte NC. I wrote my first major web app in Cold Fusion (an ecom app) at that time. In 2006 I left Charlotte and moved down to Columbia where starting working as a developer, freelancer and consultant. Currently I am working as a freelance developer and DevOps consultant!!


Running Node JS with Apache

So, in case you have not noticed, I have swapped the blog out again =). It is currently using Ghost, which is coded in Node JS. I’ve been playing a bit more lately with Node and I am enjoying it greatly. In setting up my blog, I have learned a few things and I thought that I might share them!

PM2

The first thing that we need to talk about is how to run your Node App (regardless of what it is)

Typically when we are playing with node, we run our apps with node start

This is obviously not production quality. Instead, we install pm2 via npm and use this to run a daemon of our app.

pm2 start app.js "appname"  

That loads the app. Now you can do thing like:

pm2 reload appname  

In addition to being able to easily stop and start your application, it will restart in the event of a reboot.

Also, if you are running multiple applications, pm2 gives a lot of handy usage data.

Apache

Now comes the fun part. Since the node app runs on it’s own server with it’s very own port, we have to setup proxy in apache to run it. Make sure that you have enabled proxy and proxy_http.

Then comes the vhost file:

<VirtualHost *:80>  
    ServerName blogdomain.com
    ProxyPreserveHost on
    ProxyPass / http://localhost:2368/
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/ghost 

    ErrorLog ${APACHE_LOG_DIR}/blog-error.log
    CustomLog ${APACHE_LOG_DIR}/blog-access.log combined
    <Directory "/var/www/ghost">
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>  

Now just load the conf file, reload the apache2 service and you should be good to go!

© 2024 David Duggins. All rights reserved.