summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Andersen <aaron@fosslib.net>2019-11-04 16:24:55 -0500
committerAaron Andersen <aaron@fosslib.net>2019-12-24 20:27:48 -0500
commit79215f0df1ddf4bf0db7dc4c5789f8dae9f9bb02 (patch)
tree8ceee3dc89f5c391a72389fef26adf505b3d80f5
parentd5bbb86bcb70cf3a5b252bd5d6d7d17b3e7921eb (diff)
nixos/httpd: limit serving web content to virtual hosts, convert virtualHosts option type from listOf to attrsOf, add ACME integration
-rw-r--r--nixos/doc/manual/configuration/abstractions.xml135
-rw-r--r--nixos/doc/manual/configuration/config-file.xml8
-rw-r--r--nixos/doc/manual/release-notes/rl-2003.xml22
-rw-r--r--nixos/modules/services/monitoring/nagios.nix36
-rw-r--r--nixos/modules/services/web-apps/limesurvey.nix88
-rw-r--r--nixos/modules/services/web-apps/mediawiki.nix59
-rw-r--r--nixos/modules/services/web-apps/moodle.nix54
-rw-r--r--nixos/modules/services/web-apps/wordpress.nix80
-rw-r--r--nixos/modules/services/web-apps/zabbix.nix54
-rw-r--r--nixos/modules/services/web-servers/apache-httpd/default.nix398
-rw-r--r--nixos/modules/services/web-servers/apache-httpd/per-server-options.nix401
-rw-r--r--nixos/tests/ec2.nix2
-rw-r--r--nixos/tests/haproxy.nix14
-rw-r--r--nixos/tests/hitch/default.nix2
-rw-r--r--nixos/tests/proxy.nix15
-rw-r--r--nixos/tests/upnp.nix8
16 files changed, 727 insertions, 649 deletions
diff --git a/nixos/doc/manual/configuration/abstractions.xml b/nixos/doc/manual/configuration/abstractions.xml
index 5bf0635cc1aa..df9ff2615e1a 100644
--- a/nixos/doc/manual/configuration/abstractions.xml
+++ b/nixos/doc/manual/configuration/abstractions.xml
@@ -11,50 +11,46 @@
<programlisting>
{
<xref linkend="opt-services.httpd.virtualHosts"/> =
- [ { hostName = "example.org";
- documentRoot = "/webroot";
+ { "blog.example.org" = {
+ documentRoot = "/webroot/blog.example.org";
adminAddr = "alice@example.org";
- enableUserDir = true;
- }
- { hostName = "example.org";
- documentRoot = "/webroot";
+ forceSSL = true;
+ enableACME = true;
+ enablePHP = true;
+ };
+ "wiki.example.org" = {
+ documentRoot = "/webroot/wiki.example.org";
adminAddr = "alice@example.org";
- enableUserDir = true;
- enableSSL = true;
- sslServerCert = "/root/ssl-example-org.crt";
- sslServerKey = "/root/ssl-example-org.key";
- }
- ];
+ forceSSL = true;
+ enableACME = true;
+ enablePHP = true;
+ };
+ };
}
</programlisting>
It defines two virtual hosts with nearly identical configuration; the only
- difference is that the second one has SSL enabled. To prevent this
+ difference is the document root directories. To prevent this
duplication, we can use a <literal>let</literal>:
<programlisting>
let
- exampleOrgCommon =
- { hostName = "example.org";
- documentRoot = "/webroot";
- adminAddr = "alice@example.org";
- enableUserDir = true;
+ commonConfig =
+ { adminAddr = "alice@example.org";
+ forceSSL = true;
+ enableACME = true;
};
in
{
<xref linkend="opt-services.httpd.virtualHosts"/> =
- [ exampleOrgCommon
- (exampleOrgCommon // {
- enableSSL = true;
- sslServerCert = "/root/ssl-example-org.crt";
- sslServerKey = "/root/ssl-example-org.key";
- })
- ];
+ { "blog.example.org" = (commonConfig // { documentRoot = "/webroot/blog.example.org"; });
+ "wiki.example.org" = (commonConfig // { documentRoot = "/webroot/wiki.example.com"; });
+ };
}
</programlisting>
- The <literal>let exampleOrgCommon = <replaceable>...</replaceable></literal>
- defines a variable named <literal>exampleOrgCommon</literal>. The
+ The <literal>let commonConfig = <replaceable>...</replaceable></literal>
+ defines a variable named <literal>commonConfig</literal>. The
<literal>//</literal> operator merges two attribute sets, so the
configuration of the second virtual host is the set
- <literal>exampleOrgCommon</literal> extended with the SSL options.
+ <literal>commonConfig</literal> extended with the document root option.
</para>
<para>
@@ -63,13 +59,13 @@ in
<programlisting>
{
<xref linkend="opt-services.httpd.virtualHosts"/> =
- let exampleOrgCommon = <replaceable>...</replaceable>; in
- [ exampleOrgCommon
- (exampleOrgCommon // { <replaceable>...</replaceable> })
- ];
+ let commonConfig = <replaceable>...</replaceable>; in
+ { "blog.example.org" = (commonConfig // { <replaceable>...</replaceable> })
+ "wiki.example.org" = (commonConfig // { <replaceable>...</replaceable> })
+ };
}
</programlisting>
- but not <literal>{ let exampleOrgCommon = <replaceable>...</replaceable>; in
+ but not <literal>{ let commonConfig = <replaceable>...</replaceable>; in
<replaceable>...</replaceable>; }</literal> since attributes (as opposed to
attribute values) are not expressions.
</para>
@@ -77,80 +73,29 @@ in
<para>
<emphasis>Functions</emphasis> provide another method of abstraction. For
instance, suppose that we want to generate lots of different virtual hosts,
- all with identical configuration except for the host name. This can be done
+ all with identical configuration except for the document root. This can be done
as follows:
<programlisting>
{
<xref linkend="opt-services.httpd.virtualHosts"/> =
let
- makeVirtualHost = name:
- { hostName = name;
- documentRoot = "/webroot";
+ makeVirtualHost = webroot:
+ { documentRoot = webroot;
adminAddr = "alice@example.org";
+ forceSSL = true;
+ enableACME = true;
};
in
- [ (makeVirtualHost "example.org")
- (makeVirtualHost "example.com")
- (makeVirtualHost "example.gov")
- (makeVirtualHost "example.nl")
- ];
+ { "example.org" = (makeVirtualHost "/webroot/example.org");
+ "example.com" = (makeVirtualHost "/webroot/example.com");
+ "example.gov" = (makeVirtualHost "/webroot/example.gov");
+ "example.nl" = (makeVirtualHost "/webroot/example.nl");
+ };
}
</programlisting>
Here, <varname>makeVirtualHost</varname> is a function that takes a single
- argument <literal>name</literal> and returns the configuration for a virtual
+ argument <literal>webroot</literal> and returns the configuration for a virtual
host. That function is then called for several names to produce the list of
virtual host configurations.
</para>
-
- <para>
- We can further improve on this by using the function <varname>map</varname>,
- which applies another function to every element in a list:
-<programlisting>
-{
- <xref linkend="opt-services.httpd.virtualHosts"/> =
- let
- makeVirtualHost = <replaceable>...</replaceable>;
- in map makeVirtualHost
- [ "example.org" "example.com" "example.gov" "example.nl" ];
-}
-</programlisting>
- (The function <literal>map</literal> is called a <emphasis>higher-order
- function</emphasis> because it takes another function as an argument.)
- </para>
-
- <para>
- What if you need more than one argument, for instance, if we want to use a
- different <literal>documentRoot</literal> for each virtual host? Then we can
- make <varname>makeVirtualHost</varname> a function that takes a
- <emphasis>set</emphasis> as its argument, like this:
-<programlisting>
-{
- <xref linkend="opt-services.httpd.virtualHosts"/> =
- let
- makeVirtualHost = { name, root }:
- { hostName = name;
- documentRoot = root;
- adminAddr = "alice@example.org";
- };
- in map makeVirtualHost
- [ { name = "example.org"; root = "/sites/example.org"; }
- { name = "example.com"; root = "/sites/example.com"; }
- { name = "example.gov"; root = "/sites/example.gov"; }
- { name = "example.nl"; root = "/sites/example.nl"; }
- ];
-}
-</programlisting>
- But in this case (where every root is a subdirectory of
- <filename>/sites</filename> named after the virtual host), it would have been
- shorter to define <varname>makeVirtualHost</varname> as
-<programlisting>
-makeVirtualHost = name:
- { hostName = name;
- documentRoot = "/sites/${name}";
- adminAddr = "alice@example.org";
- };
-</programlisting>
- Here, the construct <literal>${<replaceable>...</replaceable>}</literal>
- allows the result of an expression to be spliced into a string.
- </para>
</section>
diff --git a/nixos/doc/manual/configuration/config-file.xml b/nixos/doc/manual/configuration/config-file.xml
index eadafb94b8f6..7ccb5b3664ea 100644
--- a/nixos/doc/manual/configuration/config-file.xml
+++ b/nixos/doc/manual/configuration/config-file.xml
@@ -27,7 +27,7 @@
{ <xref linkend="opt-services.httpd.enable"/> = true;
<xref linkend="opt-services.httpd.adminAddr"/> = "alice@example.org";
- <xref linkend="opt-services.httpd.documentRoot"/> = "/webroot";
+ <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.localhost.documentRoot</link> = "/webroot";
}
</programlisting>
defines a configuration with three option definitions that together enable
@@ -50,7 +50,11 @@
httpd = {
enable = true;
adminAddr = "alice@example.org";
- documentRoot = "/webroot";
+ virtualHosts = {
+ localhost = {
+ documentRoot = "/webroot";
+ };
+ };
};
};
}
diff --git a/nixos/doc/manual/release-notes/rl-2003.xml b/nixos/doc/manual/release-notes/rl-2003.xml
index 10ba1c180f6f..78e5ba4a920b 100644
--- a/nixos/doc/manual/release-notes/rl-2003.xml
+++ b/nixos/doc/manual/release-notes/rl-2003.xml
@@ -327,6 +327,28 @@ services.xserver.displayManager.defaultSession = "xfce+icewm";
module.
</para>
</listitem>
+ <listitem>
+ <para>
+ The httpd module no longer provides options to support serving web content without defining a virtual host. As a
+ result of this the <link linkend="opt-services.httpd.logPerVirtualHost">services.httpd.logPerVirtualHost</link>
+ option now defaults to <literal>true</literal> instead of <literal>false</literal>. Please update your
+ configuration to make use of <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts</link>.
+ </para>
+ <para>
+ The <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.&lt;name&gt;</link>
+ option has changed type from a list of submodules to an attribute set of submodules, better matching
+ <link linkend="opt-services.nginx.virtualHosts">services.nginx.virtualHosts.&lt;name&gt;</link>.
+ </para>
+ <para>
+ This change comes with the addition of the following options which mimic the functionality of their <literal>nginx</literal> counterparts:
+ <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.&lt;name&gt;.addSSL</link>,
+ <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.&lt;name&gt;.forceSSL</link>,
+ <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.&lt;name&gt;.onlySSL</link>,
+ <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.&lt;name&gt;.enableACME</link>,
+ <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.&lt;name&gt;.acmeRoot</link>, and
+ <link linkend="opt-services.httpd.virtualHosts">services.httpd.virtualHosts.&lt;name&gt;.useACMEHost</link>.
+ </para>
+ </listitem>
</itemizedlist>
</section>
diff --git a/nixos/modules/services/monitoring/nagios.nix b/nixos/modules/services/monitoring/nagios.nix
index 6a3b97769462..4128bc12030f 100644
--- a/nixos/modules/services/monitoring/nagios.nix
+++ b/nixos/modules/services/monitoring/nagios.nix
@@ -8,6 +8,7 @@ let
nagiosState = "/var/lib/nagios";
nagiosLogDir = "/var/log/nagios";
+ urlPath = "/nagios";
nagiosObjectDefs = cfg.objectDefs;
@@ -49,12 +50,12 @@ let
''
main_config_file=${cfg.mainConfigFile}
use_authentication=0
- url_html_path=${cfg.urlPath}
+ url_html_path=${urlPath}
'';
extraHttpdConfig =
''
- ScriptAlias ${cfg.urlPath}/cgi-bin ${pkgs.nagios}/sbin
+ ScriptAlias ${urlPath}/cgi-bin ${pkgs.nagios}/sbin
<Directory "${pkgs.nagios}/sbin">
Options ExecCGI
@@ -62,7 +63,7 @@ let
SetEnv NAGIOS_CGI_CONFIG ${cfg.cgiConfigFile}
</Directory>
- Alias ${cfg.urlPath} ${pkgs.nagios}/share
+ Alias ${urlPath} ${pkgs.nagios}/share
<Directory "${pkgs.nagios}/share">
Options None
@@ -72,6 +73,10 @@ let
in
{
+ imports = [
+ (mkRemovedOptionModule [ "services" "nagios" "urlPath" ] "The urlPath option has been removed as it is hard coded to /nagios in the nagios package.")
+ ];
+
options = {
services.nagios = {
enable = mkOption {
@@ -128,13 +133,20 @@ in
";
};
- urlPath = mkOption {
- default = "/nagios";
- description = "
- The URL path under which the Nagios web interface appears.
- That is, you can access the Nagios web interface through
- <literal>http://<replaceable>server</replaceable>/<replaceable>urlPath</replaceable></literal>.
- ";
+ virtualHost = mkOption {
+ type = types.submodule (import ../web-servers/apache-httpd/per-server-options.nix);
+ example = literalExample ''
+ { hostName = "example.org";
+ adminAddr = "webmaster@example.org";
+ enableSSL = true;
+ sslServerCert = "/var/lib/acme/example.org/full.pem";
+ sslServerKey = "/var/lib/acme/example.org/key.pem";
+ }
+ '';
+ description = ''
+ Apache configuration can be done by adapting <option>services.httpd.virtualHosts</option>.
+ See <xref linkend="opt-services.httpd.virtualHosts"/> for further information.
+ '';
};
};
};
@@ -182,6 +194,8 @@ in
'';
};
- services.httpd.extraConfig = optionalString cfg.enableWebInterface extraHttpdConfig;
+ services.httpd.virtualHosts = optionalAttrs cfg.enableWebInterface {
+ ${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost { extraConfig = extraHttpdConfig; } ];
+ };
};
}
diff --git a/nixos/modules/services/web-apps/limesurvey.nix b/nixos/modules/services/web-apps/limesurvey.nix
index bd524524130d..e00a47191c6f 100644
--- a/nixos/modules/services/web-apps/limesurvey.nix
+++ b/nixos/modules/services/web-apps/limesurvey.nix
@@ -3,7 +3,7 @@
let
inherit (lib) mkDefault mkEnableOption mkForce mkIf mkMerge mkOption;
- inherit (lib) mapAttrs optional optionalString types;
+ inherit (lib) literalExample mapAttrs optional optionalString types;
cfg = config.services.limesurvey;
fpm = config.services.phpfpm.pools.limesurvey;
@@ -100,19 +100,15 @@ in
};
virtualHost = mkOption {
- type = types.submodule ({
- options = import ../web-servers/apache-httpd/per-server-options.nix {
- inherit lib;
- forMainServer = false;
- };
- });
- example = {
- hostName = "survey.example.org";
- enableSSL = true;
- adminAddr = "webmaster@example.org";
- sslServerCert = "/var/lib/acme/survey.example.org/full.pem";
- sslServerKey = "/var/lib/acme/survey.example.org/key.pem";
- };
+ type = types.submodule (import ../web-servers/apache-httpd/per-server-options.nix);
+ example = literalExample ''
+ {
+ hostName = "survey.example.org";
+ adminAddr = "webmaster@example.org";
+ forceSSL = true;
+ enableACME = true;
+ }
+ '';
description = ''
Apache configuration can be done by adapting <literal>services.httpd.virtualHosts.&lt;name&gt;</literal>.
See <xref linkend="opt-services.httpd.virtualHosts"/> for further information.
@@ -184,7 +180,7 @@ in
config = {
tempdir = "${stateDir}/tmp";
uploaddir = "${stateDir}/upload";
- force_ssl = mkIf cfg.virtualHost.enableSSL "on";
+ force_ssl = mkIf (cfg.virtualHost.addSSL || cfg.virtualHost.forceSSL || cfg.virtualHost.onlySSL) "on";
config.defaultlang = "en";
};
};
@@ -215,38 +211,36 @@ in
enable = true;
adminAddr = mkDefault cfg.virtualHost.adminAddr;
extraModules = [ "proxy_fcgi" ];
- virtualHosts = [ (mkMerge [
- cfg.virtualHost {
- documentRoot = mkForce "${pkg}/share/limesurvey";
- extraConfig = ''
- Alias "/tmp" "${stateDir}/tmp"
- <Directory "${stateDir}">
- AllowOverride all
- Require all granted
- Options -Indexes +FollowSymlinks
- </Directory>
-
- Alias "/upload" "${stateDir}/upload"
- <Directory "${stateDir}/upload">
- AllowOverride all
- Require all granted
- Options -Indexes
- </Directory>
-
- <Directory "${pkg}/share/limesurvey">
- <FilesMatch "\.php$">
- <If "-f %{REQUEST_FILENAME}">
- SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
- </If>
- </FilesMatch>
-
- AllowOverride all
- Options -Indexes
- DirectoryIndex index.php
- </Directory>
- '';
- }
- ]) ];
+ virtualHosts.${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost {
+ documentRoot = mkForce "${pkg}/share/limesurvey";
+ extraConfig = ''
+ Alias "/tmp" "${stateDir}/tmp"
+ <Directory "${stateDir}">
+ AllowOverride all
+ Require all granted
+ Options -Indexes +FollowSymlinks
+ </Directory>
+
+ Alias "/upload" "${stateDir}/upload"
+ <Directory "${stateDir}/upload">
+ AllowOverride all
+ Require all granted
+ Options -Indexes
+ </Directory>
+
+ <Directory "${pkg}/share/limesurvey">
+ <FilesMatch "\.php$">
+ <If "-f %{REQUEST_FILENAME}">
+ SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
+ </If>
+ </FilesMatch>
+
+ AllowOverride all
+ Options -Indexes
+ DirectoryIndex index.php
+ </Directory>
+ '';
+ } ];
};
systemd.tmpfiles.rules = [
diff --git a/nixos/modules/services/web-apps/mediawiki.nix b/nixos/modules/services/web-apps/mediawiki.nix
index 43edc04e1a49..8a109b39bb57 100644
--- a/nixos/modules/services/web-apps/mediawiki.nix
+++ b/nixos/modules/services/web-apps/mediawiki.nix
@@ -64,7 +64,7 @@ let
$wgScriptPath = "";
## The protocol and server name to use in fully-qualified URLs
- $wgServer = "${if cfg.virtualHost.enableSSL then "https" else "http"}://${cfg.virtualHost.hostName}";
+ $wgServer = "${if cfg.virtualHost.addSSL || cfg.virtualHost.forceSSL || cfg.virtualHost.onlySSL then "https" else "http"}://${cfg.virtualHost.hostName}";
## The URL path to static resources (images, scripts, etc.)
$wgResourceBasePath = $wgScriptPath;
@@ -290,19 +290,13 @@ in
};
virtualHost = mkOption {
- type = types.submodule ({
- options = import ../web-servers/apache-httpd/per-server-options.nix {
- inherit lib;
- forMainServer = false;
- };
- });
+ type = types.submodule (import ../web-servers/apache-httpd/per-server-options.nix);
example = literalExample ''
{
hostName = "mediawiki.example.org";
- enableSSL = true;
adminAddr = "webmaster@example.org";
- sslServerCert = "/var/lib/acme/mediawiki.example.org/full.pem";
- sslServerKey = "/var/lib/acme/mediawiki.example.org/key.pem";
+ forceSSL = true;
+ enableACME = true;
}
'';
description = ''
@@ -389,31 +383,28 @@ in
services.httpd = {
enable = true;
- adminAddr = mkDefault cfg.virtualHost.adminAddr;
extraModules = [ "proxy_fcgi" ];
- virtualHosts = [ (mkMerge [
- cfg.virtualHost {
- documentRoot = mkForce "${pkg}/share/mediawiki";
- extraConfig = ''
- <Directory "${pkg}/share/mediawiki">
- <FilesMatch "\.php$">
- <If "-f %{REQUEST_FILENAME}">
- SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
- </If>
- </FilesMatch>
-
- Require all granted
- DirectoryIndex index.php
- AllowOverride All
- </Directory>
- '' + optionalString (cfg.uploadsDir != null) ''
- Alias "/images" "${cfg.uploadsDir}"
- <Directory "${cfg.uploadsDir}">
- Require all granted
- </Directory>
- '';
- }
- ]) ];
+ virtualHosts.${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost {
+ documentRoot = mkForce "${pkg}/share/mediawiki";
+ extraConfig = ''
+ <Directory "${pkg}/share/mediawiki">
+ <FilesMatch "\.php$">
+ <If "-f %{REQUEST_FILENAME}">
+ SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
+ </If>
+ </FilesMatch>
+
+ Require all granted
+ DirectoryIndex index.php
+ AllowOverride All
+ </Directory>
+ '' + optionalString (cfg.uploadsDir != null) ''
+ Alias "/images" "${cfg.uploadsDir}"
+ <Directory "${cfg.uploadsDir}">
+ Require all granted
+ </Directory>
+ '';
+ } ];
};
systemd.tmpfiles.rules = [
diff --git a/nixos/modules/services/web-apps/moodle.nix b/nixos/modules/services/web-apps/moodle.nix
index ac59f9e0012a..595d070d940a 100644
--- a/nixos/modules/services/web-apps/moodle.nix
+++ b/nixos/modules/services/web-apps/moodle.nix
@@ -32,7 +32,7 @@ let
'dbcollation' => 'utf8mb4_unicode_ci',
);
- $CFG->wwwroot = '${if cfg.virtualHost.enableSSL then "https" else "http"}://${cfg.virtualHost.hostName}';
+ $CFG->wwwroot = '${if cfg.virtualHost.addSSL || cfg.virtualHost.forceSSL || cfg.virtualHost.onlySSL then "https" else "http"}://${cfg.virtualHost.hostName}';
$CFG->dataroot = '${stateDir}';
$CFG->admin = 'admin';
@@ -140,19 +140,15 @@ in
};
virtualHost = mkOption {
- type = types.submodule ({
- options = import ../web-servers/apache-httpd/per-server-options.nix {
- inherit lib;
- forMainServer = false;
- };
- });
- example = {
- hostName = "moodle.example.org";
- enableSSL = true;
- adminAddr = "webmaster@example.org";
- sslServerCert = "/var/lib/acme/moodle.example.org/full.pem";
- sslServerKey = "/var/lib/acme/moodle.example.org/key.pem";
- };
+ type = types.submodule (import ../web-servers/apache-httpd/per-server-options.nix);
+ example = literalExample ''
+ {
+ hostName = "moodle.example.org";
+ adminAddr = "webmaster@example.org";
+ forceSSL = true;
+ enableACME = true;
+ }
+ '';
description = ''
Apache configuration can be done by adapting <option>services.httpd.virtualHosts</option>.
See <xref linkend="opt-services.httpd.virtualHosts"/> for further information.
@@ -241,22 +237,20 @@ in
enable = true;
adminAddr = mkDefault cfg.virtualHost.adminAddr;
extraModules = [ "proxy_fcgi" ];
- virtualHosts = [ (mkMerge [
- cfg.virtualHost {
- documentRoot = mkForce "${cfg.package}/share/moodle";
- extraConfig = ''
- <Directory "${cfg.package}/share/moodle">
- <FilesMatch "\.php$">
- <If "-f %{REQUEST_FILENAME}">
- SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
- </If>
- </FilesMatch>
- Options -Indexes
- DirectoryIndex index.php
- </Directory>
- '';
- }
- ]) ];
+ virtualHosts.${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost {
+ documentRoot = mkForce "${cfg.package}/share/moodle";
+ extraConfig = ''
+ <Directory "${cfg.package}/share/moodle">
+ <FilesMatch "\.php$">
+ <If "-f %{REQUEST_FILENAME}">
+ SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
+ </If>
+ </FilesMatch>
+ Options -Indexes
+ DirectoryIndex index.php
+ </Directory>
+ '';
+ } ];
};
systemd.tmpfiles.rules = [
diff --git a/nixos/modules/services/web-apps/wordpress.nix b/nixos/modules/services/web-apps/wordpress.nix
index 13d21a0b4aed..ad4f39fbf52c 100644
--- a/nixos/modules/services/web-apps/wordpress.nix
+++ b/nixos/modules/services/web-apps/wordpress.nix
@@ -3,7 +3,7 @@
let
inherit (lib) mkDefault mkEnableOption mkForce mkIf mkMerge mkOption types;
inherit (lib) any attrValues concatMapStringsSep flatten literalExample;
- inherit (lib) mapAttrs' mapAttrsToList nameValuePair optional optionalAttrs optionalString;
+ inherit (lib) mapAttrs mapAttrs' mapAttrsToList nameValuePair optional optionalAttrs optionalString;
eachSite = config.services.wordpress;
user = "wordpress";
@@ -209,18 +209,12 @@ let
};
virtualHost = mkOption {
- type = types.submodule ({
- options = import ../web-servers/apache-httpd/per-server-options.nix {
- inherit lib;
- forMainServer = false;
- };
- });
+ type = types.submodule (import ../web-servers/apache-httpd/per-server-options.nix);
example = literalExample ''
{
- enableSSL = true;
adminAddr = "webmaster@example.org";
- sslServerCert = "/var/lib/acme/wordpress.example.org/full.pem";
- sslServerKey = "/var/lib/acme/wordpress.example.org/key.pem";
+ forceSSL = true;
+ enableACME = true;
}
'';
description = ''
@@ -304,41 +298,37 @@ in
services.httpd = {
enable = true;
extraModules = [ "proxy_fcgi" ];
- virtualHosts = mapAttrsToList (hostName: cfg:
- (mkMerge [
- cfg.virtualHost {
- documentRoot = mkForce "${pkg hostName cfg}/share/wordpress";
- extraConfig = ''
- <Directory "${pkg hostName cfg}/share/wordpress">
- <FilesMatch "\.php$">
- <If "-f %{REQUEST_FILENAME}">
- SetHandler "proxy:unix:${config.services.phpfpm.pools."wordpress-${hostName}".socket}|fcgi://localhost/"
- </If>
- </FilesMatch>
-
- # standard wordpress .htaccess contents
- <IfModule mod_rewrite.c>
- RewriteEngine On
- RewriteBase /
- RewriteRule ^index\.php$ - [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]
- </IfModule>
-
- DirectoryIndex index.php
- Require all granted
- Options +FollowSymLinks
- </Directory>
-
- # https://wordpress.org/support/article/hardening-wordpress/#securing-wp-config-php
- <Files wp-config.php>
- Require all denied
- </Files>
- '';
- }
- ])
- ) eachSite;
+ virtualHosts = mapAttrs (hostName: cfg: mkMerge [ cfg.virtualHost {
+ documentRoot = mkForce "${pkg hostName cfg}/share/wordpress";
+ extraConfig = ''
+ <Directory "${pkg hostName cfg}/share/wordpress">
+ <FilesMatch "\.php$">
+ <If "-f %{REQUEST_FILENAME}">
+ SetHandler "proxy:unix:${config.services.phpfpm.pools."wordpress-${hostName}".socket}|fcgi://localhost/"
+ </If>
+ </FilesMatch>
+
+ # standard wordpress .htaccess contents
+ <IfModule mod_rewrite.c>
+ RewriteEngine On
+ RewriteBase /
+ RewriteRule ^index\.php$ - [L]
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteCond %{REQUEST_FILENAME} !-d
+ RewriteRule . /index.php [L]
+ </IfModule>
+
+ DirectoryIndex index.php
+ Require all granted
+ Options +FollowSymLinks
+ </Directory>
+
+ # https://wordpress.org/support/article/hardening-wordpress/#securing-wp-config-php
+ <Files wp-config.php>
+ Require all denied
+ </Files>
+ '';
+ } ]) eachSite;
};
systemd.tmpfiles.rules = flatten (mapAttrsToList (hostName: cfg: [
diff --git a/nixos/modules/services/web-apps/zabbix.nix b/nixos/modules/services/web-apps/zabbix.nix
index 09538726b7cd..ee8447810c6d 100644
--- a/nixos/modules/services/web-apps/zabbix.nix
+++ b/nixos/modules/services/web-apps/zabbix.nix
@@ -113,19 +113,15 @@ in
};
virtualHost = mkOption {
- type = types.submodule ({
- options = import ../web-servers/apache-httpd/per-server-options.nix {
- inherit lib;
- forMainServer = false;
- };
- });
- example = {
- hostName = "zabbix.example.org";
- enableSSL = true;
- adminAddr = "webmaster@example.org";
- sslServerCert = "/var/lib/acme/zabbix.example.org/full.pem";
- sslServerKey = "/var/lib/acme/zabbix.example.org/key.pem";
- };
+ type = types.submodule (import ../web-servers/apache-httpd/per-server-options.nix);
+ example = literalExample ''
+ {
+ hostName = "zabbix.example.org";
+ adminAddr = "webmaster@example.org";
+ forceSSL = true;
+ enableACME = true;
+ }
+ '';
description = ''
Apache configuration can be done by adapting <literal>services.httpd.virtualHosts.&lt;name&gt;</literal>.
See <xref linkend="opt-services.httpd.virtualHosts"/> for further information.
@@ -190,23 +186,21 @@ in
enable = true;
adminAddr = mkDefault cfg.virtualHost.adminAddr;
extraModules = [ "proxy_fcgi" ];
- virtualHosts = [ (mkMerge [
- cfg.virtualHost {
- documentRoot = mkForce "${cfg.package}/share/zabbix";
- extraConfig = ''
- <Directory "${cfg.package}/share/zabbix">
- <FilesMatch "\.php$">
- <If "-f %{REQUEST_FILENAME}">
- SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
- </If>
- </FilesMatch>
- AllowOverride all
- Options -Indexes
- DirectoryIndex index.php
- </Directory>
- '';
- }
- ]) ];
+ virtualHosts.${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost {
+ documentRoot = mkForce "${cf