Self-hosting a Ghost Blog + Independent Landing Page + YOURLS (Custom link shortener) [i.e. Growing up from Medium :P]

After MONTHS, literally months and recent weeks of research followed by being overwhelmed/burnt out/walking kilometers in solitude because of the immense self-hosting and blogging knowledge/options out there, from which commenting system to use (Disqus, Facebook comments, WP comments), which blogging software to use (Ghost versus WordPress), to most importantly, which web server would give the most optimal performance and cater for my needs to host this thing on (mainly Apache or Nginx, or a combination), and now after really wanting my own hosted custom URL shortener for mainly link/URL analytics, control and presentation purposes when sharing my 2013-based website, I’ve finally pulled everything together and done it! I’ve effectively set up the robust foundations for what will now be my personal *Runescape* home (and hopefully many more homes) on the web.
A Little Web Background About Me
Before 2012, I was pretty hesitant to even personally self-host anything on the web in fear or privacy being forever given up (by Google Cache [you could use robots.txt] and Wayback Machine [sorry, this one eats the entire way daily, there’s no escaping it even if you wanted to]— once it’s out there, it’s out there for good, sure, you can take down its original source/host, but by default, fragments will still remain in aforementioned achieved repositories as well as any screenshots anyone ever took). I had Facebook since Feb 2010, but Facebook is by default (for now) a predominately closed network unless you set your Facebook Profile to be visible by Search Engines or use a public Page. After a lot of more sharing of tech, science and engineering news on my Facebook timeline, I decided to open up my timeline to the public and make that visible to Search Engines too, we’re only here once, may as well fully embrace the opportunities the web has to efficiently give to us, but this has been both a blessing and a curse, on one hand, it’s efficient coverage of endless seas of industry and world information, or the other hand, is a MASSIVE, and I mean MASSIVE time suck if you try and keep up with it all, even if you’re indirectly doing it by just a 2 min browse of the Facebook feed, you’ll be inclined to share something you personally see interesting. It’s physcology 101 and Facebook knows that.
Yeah, the web is initially a very intimidating place, especially when we were told not to ever put our full names on the internet just a little 10 years ago back in 2005 when I first made my email address (and also, my Dad was always very privacy scared, and that sort of flowed onto me for a lot of years, HELL, I used to think people could easily intercept Mobile Signals floating in the air while on the train,yeah, you know those data 3G/HSPA/4g ones), but that all changed when I met a Web Developer at university and started to learn more about how IT actually works, who would have thought 10 years later I’d be actually hosting a fully-fledged blog on the world W-I-D-E web.
I thought I’d pop this on here, just in case anyone else wants a read as well. I’ve been meaning to get a blog out there + YOURLS for sometime now, but just haven’t had the full commitment… until now.
The Plumbing Life of Web Hosting:
Goal: To host YOURLs (PHP script) + personal landing page (static HTML/CSS/JS) + a Ghost blog (NodeJS).
How I initially thought about doing it:
- Thought about creating two VPSs (Droplets w/ DigitalOcean), it doubles the operational costs (from $5 to $10 /m), but allows the flexibility of having two distinct IP addresses which can easily point to different subdirectories or subdomains, with both Nginx and Apache HTTP Server being able to serve on the default HTTP port 80.
arstechnica.com/civis/viewtopic.php?t=1115813 howtoinstallghost.com/how-to-host-ghost-on-an-apache-subdomain.
2. Then I thought about hosting it all on one VPS, with Apache (for YOURLS) and Ngnix (for Ghost blog + Personal site) side by side, listening on the SAME port 80 and using reverse proxy to node.js. (http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache). [Really stupid idea putting Apache in front of Nginx]
3. Then I thought about putting Ngnix in front of Apache (since Ngnix is more lightweight and will be doing more heavy lifting i.e. serving blog and static pages — digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-for-apache kbeezie.com/apache-with-nginx/).
4. And then I figured, why not just use a LEMP (Linux, Ngnix, MySQL & PHP) stack? Hah! :D This might actually work. Don’t even need Apache at all. (I was thinking too high level about web server software before, rather than just deploying language libraries). (digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12–04)
5. *re-reads YOURLS requirements* Oh no wait, Apache is still confusingly required for mod_rewrite. (i.e. I can’t just get by with JUST a php-fpm http://php-fpm.org/ [PHP CGI]). Looks like it’s back to trusty option 3. (Maybe if one day a proper custom URL shortener is written (https://www.google.com.au/search?q=NodeJS+URL+shortener http://codecanyon.net/item/nodejs-url-shortener/8928981) in nodeJS, we’d all save a bunch of treacherous time).
6. Finds an official github thread (https://github.com/YOURLS/YOURLS/issues/1715) on YOURLS’ wiki that it IS possible to setup YOURLS without Apache; Nginx with PHP CGI, documented by an official wiki blog, sweet! *Hi-Five* https://github.com/YOURLS/YOURLS/wiki/Nginx-configuration
7. Finds out YOURLS utilises the domain name you host it on for its short links. i.e. If I want scal.ro to be my short link, I need to HOST YOURLS on that same domain name. I thought YOURLS could just point to the DNS of scal.ro. So now I start thinking about step 1 again with 2 VPSs for 2 distinct IP addresses.
This introduces a new issue; how will scal.ro redirect to my canonical URL: stefancaliaro.com/ when I want YOURLS to be hosted in the root scal.ro directory and it also needs to listen to port 80 to redirect links by the default browser HTTP port 80, which I quickly found a solution to with a bit of hosting thinking and searches. Bam: http://stackoverflow.com/questions/9336261/nginx-rewrite-only-when-root-domain Turns out we can write a Nginx condition
location / {
rewrite / http://www.domain.com/ permanent;
}
to redirect ONLY the root of a domain, and no other subdirectories, SWEET STUFF! :D more on Nginx location: http://nginx.org/en/docs/http/ngx_http_core_module.html#location
8. Later that night… Virtual Hosts (server blocks in Nginx) pops into my head running on a LEMP stack! This will allow me to run multiple domain names from a single VPS/IP address, making it cost & energy efficient with minimal overhead, we did it! (Pretty much shared hosting, only this time, I’m controlling the root of my VPS, which gives me unprecedented configuration options over just named-based shared hosting http://en.wikipedia.org/wiki/Shared_web_hosting_service#Name-based). Bazinga! We finally made the theory to satisfy all of the requirements, now lets execute it! :D
8.5. But wait a minute, what if my VPS’s IP was DDoS’d, or I all of a sudden (on the extremely rare occasion) received more traffic than I could serve, would my server just crash and die? Yep; it would be blown over in the wind. The solution? Free CloudFlare CDN. https://www.cloudflare.com/ddos
Disclaimer: I wrote this back in February 2015 and just never felt that it was finished enough to publish, so I held off from publishing it until all the way until now… July 2016. I have researched more options and topics than what I’ve mentioned here, but for brevity, this post is already a good length as it is.
Hopefully if anyone has any more recommendations on options or hosting solutions, feel free to throw a comment up. Thanks! And no, I still don’t have a blog (hah), between work, uni, life in general, I just haven’t been able to fully (I’m at about 70% justification in having a few setup) justify and pull myself to one yet.
Thanks for reading.
View the original discussion on Medium ↗







Join the conversation
Comments and reactions use GitHub. Sign in to join in, and keep the discussion thoughtful and respectful.
View discussions on GitHub ↗