Serving Static Files Alongside Ghost


If you have a file, or collection of files that you would like to host alongside Ghost, you can do this by making a couple adjustments to your Nginx configuration. Here are two examples on how to do this for a single file, or folder of assets in Nginx and Apache:

Nginx

Say you wanted a custom sitemap, what we need to do is have blog.com/sitemap.xml be pointing to this file (file located on the server at /var/www/sitemap.xml). In your Nginx conf, add this near the end:

location ~ ^/(sitemap.xml) {
        root /var/www;
}

If you need to serve a directory of static assets instead of just one file, you can use this snippet instead:

location ^~ /files {
        root /var/www;
}

Here is an example of what a full Nginx configuration file including the location for our sitemap and folder would look like:

server {
        listen 80;
        listen 443 ssl;

        ssl_certificate /etc/nginx/ssl/allghostthemes/allghostthemes.com.crt;
        ssl_certificate_key /etc/nginx/ssl/allghostthemes/allghostthemes.com.pem;
        ssl_protocols        SSLv3 TLSv1;
        ssl_ciphers HIGH:!aNULL:!MD5;

        server_name allghostthemes.com www.allghostthemes.com;

        location / {
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   Host      $http_host;
                proxy_pass         http://127.0.0.1:2368;
        }

        location ~ ^/(sitemap.xml) {
                root /var/www;
        }

        location ^~ /files {
                root /var/www;
        }
}

Apache

If you are using Apache instead of Nginx you can do the same thing with the following snippet:

ProxyPass        /sitemap.xml !

If you need to serve a directory of static assets you can use this snippet instead:

ProxyPass        /project/ !

And here is a full Apache site config with the sitemap.xml being served by Apache:

NameVirtualHost *:80
<VirtualHost *:80>
     ServerName your-url.com
     ServerAlias www.your-url.com
     ProxyRequests off

     ProxyPass        /sitemap.xml !
     ProxyPass        /project/ !

     ProxyPass / http://127.0.0.1:2368/
     ProxyPassReverse / http:/127.0.0.1:2368/
</VirtualHost>