Run Ghost blog as subfolder of website running on node http-server

2.1k views Asked by At

First, forgive my lack of understanding of Joyent's smartmachine instance. I am running a free dev tier smartmachine instance of NodeJS for this scenario.

I am running a website at [path]/server/public/ on the filesystem via http-server and I want to simultaneously run a Ghost blog at [path]/server/public/blog/, both on port 80.

Is this possible? How would I accomplish it?

3

There are 3 answers

0
jmingov On BEST ANSWER

Setting up a thin wrapper using express can be a good solution (as Paul recommends), but can be a mess if you end with a big application with a lot of "diferennt services".

Instead ill go for a proxy (NGINX for example) on top of all my services.

With this solution, if a service fails, the rest no since they are decoupled.

You can listen on port 80 and proxy internally to each service:port.

Something like:

0.0.0.0:80 ---> Proxy
                  └──path: /     ─── localhost:3000  (Main Web)
                  └──path: /blog ─── localhost:4000 (Ghost)
                  ...
5
Paul On

If your other website is an express based site, the easiest thing would probably be to include your ghost app in the same source tree (in a subfolder perhaps). Express apps can be mounted as middleware to other express apps, so you could then add a route to your main site like:

var ghost = require('./path/to/ghost');
app.use('/blog', ghost);
2
Rahat Mahbub On

Assuming you have followed "Install from zip (fastest & best for bloggers)" from https://github.com/tryghost/Ghost and you are serving static content from /public/ with http-server.

My solution is to use Ghost's Express server to serve your content:

Download Ghost.zip and unzip at [path]/server/

Open up your Ghost's config.js file and change the url in development from http://localhost:2368 to http://localhost:2368/blog/

Now open open the index.js file in the same directory and add the following:

parentApp.use(express.static(__dirname + '/public'));

after: parentApp = express();

where '/public' is the directory containing your static content.

Now, if you go to: http://localhost:2368 you will find your website and your blog will be at http://localhost:2368/blog/

To change to production, you need to make the appropriate changes and start with NODE_ENV=production npm start. To change to port 80, you will only need to change the port inside config.js and this will serve both your site and the blog on 80. This will obviously give you insufficient permission issue and there's tonne of tutorials that show you how to setup Node.js on port 80 so follow that.