Multiple domains on single writefreely self-hosted instance
Initial setup
- Writefreely installed, running on http://localhost:8080
- config.ini variable host is e.g. https://wfsite.com
- Nginx reverse proxy set up to proxy external requests from https://wfsite.com to http://localhost:8080
- Multiple blogs already set up (required setting single_user false and max_blogs 0 or > 1)
- first one (using username as short code) at https://wfsite.com/user
- second one at https://wfsite.com/japanese
- third one at https://wfsite.com/micro
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:
- Blog 1: https://wfsite.com/user/ -> http://localhost:8080/user/
- Blog 2: https://wfsite.com/japanese/ -> http://localhost:8080/japanese/
- Blog 3: https://wfsite.com/micro/ -> http://localhost:8080/micro/
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.
- Blog 1: https://code.wfsite.com -> http://localhost:8080/code/
- Blog 2: https://japanese.wfsite.com -> http://localhost:8080/japanese/
- Blog 3: https://micro.wfsite.com -> http://localhost:8080/micro/
Configure different domain for blog
Set up DNS A records for required domain
- Create nginx config for domain e.g.
/etc/nginx/sites-available/micro.wfsite.com - 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_passredirects root to subdirectorysub_filterrewrites all URLs in response containing subdirectory to root- Symlink:
sudo ln -s /etc/nginx/sites-available/micro.wfsite.com /etc/nginx/sites-enabled/micro.wfsite.com - Validate configuration:
sudo nginx -t - Restart nginx:
sudo systemctl restart nginx - Blog should now be available on non-secure URL e.g. http://micro.wfsite.com
Generate SSL cert for new domain
sudo certbot --nginx -d micro.wfsite.com- Choose 2 to redirect all HTTP requests to HTTPS
- Blog should now be available on secure URL e.g. https://micro.wfsite.com