Multiple domains on single writefreely self-hosted instance

Multiple domains on single writefreely self-hosted instance
Photo by Naufan Rusyda Faikar / Unsplash

Initial setup

  1. Writefreely installed, running on http://localhost:8080
  2. config.ini variable host is e.g. https://wfsite.com
  3. Nginx reverse proxy set up to proxy external requests from https://wfsite.com to http://localhost:8080
  4. Multiple blogs already set up (required setting single_user false and max_blogs 0 or > 1)

Current reverse proxy redirect

Blogs and admin functionality at single domain which in turn is proxied to local server i.e. https://wfsite.com/* -> http://localhost:8080/*

In effect this means:

Additionally required redirects

Previous URLs will remain as well as access to admin functionality, but additional URLs can alternatively be used to access blogs (note - will be read only, no admin panels will appear - rewrites in JavaScript most likely needed for that - may tackle in the future).

Although requests for CSS, JS etc will continue to go via previous domain, URL and links will be exclusively for the new domain, so user should never see the other domain in normal use.

Configure different domain for blog

Set up DNS A records for required domain

  1. Create nginx config for domain e.g. /etc/nginx/sites-available/micro.wfsite.com
  2. Contents as per usual reverse proxy nginx configuration example given in writefreely docs BUT location / section becomes:
location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://127.0.0.1:8080/micro/;
    sub_filter '/micro/' '/';
    sub_filter_once off;
    proxy_redirect off;
}
    • proxy_pass redirects root to subdirectory
    • sub_filter rewrites all URLs in response containing subdirectory to root
  1. Symlink: sudo ln -s /etc/nginx/sites-available/micro.wfsite.com /etc/nginx/sites-enabled/micro.wfsite.com
  2. Validate configuration: sudo nginx -t
  3. Restart nginx: sudo systemctl restart nginx
  4. Blog should now be available on non-secure URL e.g. http://micro.wfsite.com

Generate SSL cert for new domain

  1. sudo certbot --nginx -d micro.wfsite.com
    • Choose 2 to redirect all HTTP requests to HTTPS
  2. Blog should now be available on secure URL e.g. https://micro.wfsite.com