Zotonic has the capability of serving more than one site at a time. You can have multiple sites enabled, each with its own set of templates, database and URL dispatch rules.
A site’s folder contains at least the following:
Like a Zotonic module, the name of a Zotonic site must be valid as a simple Erlang atom: it should be lowercase and only contain letters, numbers and the underscore character.
Internally, sites are treated no different from a Zotonic module. In fact, they function in an identical way, and as such, can contain all kinds of resources (templates, dispatch rules, etc.) that a normal module also has. The only difference is that site names do not need to be prefixed with mod_ and sites have an extra config file in their base directory. A site’s mod_prio metadata attribute is usually set to 1, to make sure that it is the first module where Zotonic looks for template lookups and the like.
The config file is the central configuration file for your site. Its syntax is the Erlang term format, essentially it is a big proplist with different configuration options.
New in version 0.10: Each option must be specified at most once (per file). Using a option key multiple times are no longer supported (was only used by the hostalias option) and any duplicates will be silently dropped. Additional config options are read from files under config.d/.
All files under the config.d/ folder in the site’s folder are loaded to extend/override config options from the site config file. So if the same key is present in both config and config.d/some-file, then the value from the latter will be used.
The files under config.d/ are read in alphabetical order.
The following options can be configured:
This config key specifies the hostname+port part of the site’s URL, to determine to which site an incoming request belongs to (since they all come in on the same port).
If you run Zotonic on port 80, or if you put a web-frontend like varnish in front of your zotonic, you can leave out the port number, and just put the hostname in there. See the Deployment chapter on how to set up Zotonic for production environments.
Note: The hostname does not specify on which port Zotonic will listen! That information comes from the ZOTONIC_PORT environment variable, which, when absent, default to port 8000. Zotonic can (currently) listen on one TCP port for HTTP connections. For HTTPS, see the mod_ssl chapter.
New in version 0.10: The hostalias option now holds a list of aliases.
The host aliases allow you to specify extra aliases for your site. This comes in handy if you have registered yoursite.com, yoursite.net and yoursite.org, and all want them to be served the same site. Mind you that Zotonic will always redirect from a hostalias to the real hostname of the site. This is done to prevent content duplication: it is good web practice to let your content live on a single URL only.
You can specify multiple host aliases; for that, just add the different hostalias options to the list:
{hostalias, ["example.com", "www.example.com",
"example.net", "www.example.net"]},
New in version 0.10: To inherit the list of modules from a skeleton, add a {skeleton, <name>} and it will install the list of modules from that skeleton as well.
The list of installed modules will be updated on each site start, e.g. when you add a module to the install_modules list, it will be installed automatically when you restart the site.
The hostname that will be used for streaming comet/websocket requests. This hostname will be used in the browser for the stream connections instead of the main hostname, to circumvent browser limitations on the number of open sockets per host. For example:
{streamhost, "stream.example.com"}
The hostname that will be used for websocket requests. This hostname will be used in the browser for setting up the websocket connection. It can be used to configure a different port number for the websocket connection. For example:
{websockethost, "example.com:443"}
New in version 0.10.
The following options for your site config specify how it connects to the database:
These properties mostly speak for themselves, hopefully.
The dbschema is the name of the database schema (which is kind of a namespace for tables in Postgres); see Tip: multiple sites using one database below for an explanation. By default, public is used as the schema name.
The dbdriver is the name of the database driver module. Currently this defaults to z_db_pgsql. Other driver options are not yet implemented.
It is also possible to add m_config values for modules to the site’s user/sitename/config file. To do this, add clauses like this to the site’s config:
{mod_foo, [{key, value}, ...]}
For instance, to set the mod_ssl.listen_port and mod_ssl.is_secure configuration options from mod_ssl, do:
{mod_ssl, [{listen_port, 443}, {is_secure, true}]}
After you make changes to the site config you have to restart your site for them to have effect. From the Zotonic shell, do:
z_sites_manager:restart(yoursitename).
to restart your site.
In Zotonic, a single PostgreSQL database can host the data of multiple web sites. This does not work using table prefixing (like Wordpress does for example), but instead, Zotonic uses Postgres’ native feature database schemas to support this.
A database schema is basically another database inside your database: it’s a namespace in which tables live. By default, your tables live in the namespace called PUBLIC, but it’s quite easy to create another schema:
CREATE SCHEMA anothersite;
GRANT ALL ON SCHEMA anothersite TO yourdatabaseuser;
And then in your site config put a {dbschema, "anothersite"} entry next to the regular database config keys. Restart zotonic and off you go.