]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/patrick_fodella/altermondia.nix
Migrate php sessions to redis
[perso/Immae/Config/Nix.git] / modules / private / websites / patrick_fodella / altermondia.nix
1 { lib, pkgs, config, ... }:
2 let
3 cfg = config.myServices.websites.patrick_fodella.altermondia;
4 varDir = "/var/lib/ftp/patrick_fodella/altermondia";
5 apacheUser = config.services.httpd.Prod.user;
6 apacheGroup = config.services.httpd.Prod.group;
7 binEnvPaths = [ pkgs.zip ];
8 binEnv = pkgs.buildEnv { paths = binEnvPaths; name = "bin-env";};
9 in {
10 options.myServices.websites.patrick_fodella.altermondia.enable = lib.mkEnableOption "enable Patrick Fodella Altermondia's website";
11
12 config = lib.mkIf cfg.enable {
13 services.webstats.sites = [ { name = "altermondia.org"; } ];
14
15 systemd.services.phpfpm-patrick_fodella_altermondia.after = lib.mkAfter [ "mysql.service" ];
16 systemd.services.phpfpm-patrick_fodella_altermondia.wants = [ "mysql.service" ];
17 services.phpfpm.pools.patrick_fodella_altermondia = {
18 user = apacheUser;
19 group = apacheGroup;
20 settings = {
21 "listen.owner" = apacheUser;
22 "listen.group" = apacheGroup;
23
24 "pm" = "dynamic";
25 "pm.max_children" = "20";
26 "pm.start_servers" = "2";
27 "pm.min_spare_servers" = "1";
28 "pm.max_spare_servers" = "3";
29
30 "env[BIN_ENV]" = "${binEnv}/bin";
31 "php_admin_value[open_basedir]" = "${binEnv}:${builtins.concatStringsSep ":" binEnvPaths}:${varDir}:/tmp";
32 "php_admin_value[session.save_handler]" = "redis";
33 "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=PatrickFodella:Altermondia:'";
34 };
35 phpOptions = config.services.phpfpm.phpOptions + ''
36 disable_functions = "mail"
37 '';
38 phpPackage = pkgs.php72.withExtensions({ enabled, all }: enabled ++ [all.redis]);
39 };
40 services.websites.env.production.modules = [ "proxy_fcgi" ];
41 services.websites.env.production.vhostConfs.patrick_fodella_altermondia = {
42 certName = "patrick_fodella";
43 addToCerts = true;
44 hosts = ["altermondia.org" "www.altermondia.org" ];
45 root = varDir;
46 extraConfig = [
47 ''
48 Use Stats altermondia.org
49
50 RewriteEngine on
51 RewriteCond "%{HTTP_HOST}" "!^altermondia\.org$" [NC]
52 RewriteRule ^(.+)$ https://altermondia.org$1 [R=302,L]
53
54 <FilesMatch "\.php$">
55 SetHandler "proxy:unix:${config.services.phpfpm.pools.patrick_fodella_altermondia.socket}|fcgi://localhost"
56 </FilesMatch>
57
58 <Location /xmlrpc.php>
59 AllowOverride None
60 Require all denied
61 </Location>
62 <Directory ${varDir}>
63 DirectoryIndex index.php index.htm index.html
64 Options Indexes FollowSymLinks MultiViews Includes
65 AllowOverride all
66 Require all granted
67 </Directory>
68 ''
69 ];
70 };
71 };
72 }
73