I’m an edge-case, self-hosting this website’s Ghost installation on a DigitalOcean using Apache instead of the recommended NGINX. My reason was due to cost and preference - I already had a droplet running with Apache, and I’m less familiar with NGINX.
Unlike WordPress, Ghost can’t serve static files by merely dropping them into your web server’s document directory. While Ghost generates stuff like the sitemap.xml and RSS feeds, it doesn’t generate the ads.txt file Google tells me I need when using Adsense. To overcome this limitation, you must manually edit your web server’s config files with the ProxyPass command to explicitly allow it to serve the file. That might be enough for NGINX, but not Apache — at least in Ubuntu 18.04.
Unfortunately, most tutorials on the subject are for NGINX only, and the only Apache tutorial I found didn’t work. After some experimentation, I solved the issue by explicitly declaring the location of the ghost installation in the Apache Conf file using the DocumentRoot directive. Since Ghost works with Apache through a Proxy, it doesn’t need this directive declared to work, so in most examples, it’s omitted from the file.
Here’s an extract of my Ghost installation’s Apache Config file.
<VirtualHost *:443> ServerName chrisrosser.net DocumentRoot /var/www/ghost ProxyRequests off ProxyPass /ads.txt ! ProxyPass / http://127.0.0.1:2368/ ProxyPassReverse / http:/127.0.0.1:2368/ ProxyPreserveHost On </VirtualHost>
Every tutorial I read correctly asserted the need to include, ProxyPass /ads.txt !; however, they ignored the required DocumentRoot directive. Add this, point it to your Ghost’s installation directory then reload Apache and restart Ghost. Your static file should then be available.
I hope this helps someone!
If you enjoy articles like this one, support me by becoming a Scriptorium member. Members get access to all content and more.