aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/patrick_fodella/production.nix
blob: 2812cf7b402a9a6e54660aaad043b96fb22b0589 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{ lib, pkgs, config,  ... }:
let
  cfg = config.myServices.websites.patrick_fodella.production;
  varDir = "/var/lib/ftp/patrick_fodella";
  apacheUser = config.services.httpd.Prod.user;
  apacheGroup = config.services.httpd.Prod.group;
in {
  options.myServices.websites.patrick_fodella.production.enable = lib.mkEnableOption "enable Patrick Fodella's website";

  config = lib.mkIf cfg.enable {
    services.webstats.sites = [ { name = "ecolyeu-pessicart-nice.fr"; } ];

    system.activationScripts.patrick_fodella = {
      deps = [ "httpd" ];
      text = ''
        install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d /var/lib/php/sessions/patrick_fodella
        '';
    };
    systemd.services.phpfpm-patrick_fodella.after = lib.mkAfter [ "mysql.service" ];
    systemd.services.phpfpm-patrick_fodella.wants = [ "mysql.service" ];
    services.phpfpm.pools.patrick_fodella = {
      user = apacheUser;
      group = apacheGroup;
      settings = {
        "listen.owner" = apacheUser;
        "listen.group" = apacheGroup;

        "pm" = "ondemand";
        "pm.max_children" = "5";
        "pm.process_idle_timeout" = "60";

        "php_admin_value[open_basedir]" = "/var/lib/php/sessions/patrick_fodella:${varDir}:/tmp";
        "php_admin_value[session.save_path]" = "/var/lib/php/sessions/patrick_fodella";
      };
      phpOptions = config.services.phpfpm.phpOptions + ''
        disable_functions = "mail"
      '';
      phpPackage = pkgs.php72;
    };
    services.websites.env.production.modules = [ "proxy_fcgi" ];
    services.websites.env.production.vhostConfs.patrick_fodella = {
      certName     = "patrick_fodella";
      certMainHost = "ecolyeu-pessicart-nice.fr";
      hosts        = ["ecolyeu-pessicart-nice.fr" "www.ecolyeu-pessicart-nice.fr" ];
      root         = varDir;
      extraConfig  = [
        ''
        Use Stats ecolyeu-pessicart-nice.fr

        RewriteEngine on
        RewriteCond "%{HTTP_HOST}" "!^www\.ecolyeu-pessicart-nice\.fr$" [NC]
        RewriteRule ^(.+)$ https://www.ecolyeu-pessicart-nice.fr$1 [R=302,L]

        <FilesMatch "\.php$">
          SetHandler "proxy:unix:${config.services.phpfpm.pools.patrick_fodella.socket}|fcgi://localhost"
        </FilesMatch>

        <Location /xmlrpc.php>
          AllowOverride None
          Require all denied
        </Location>
        <Directory ${varDir}>
          DirectoryIndex index.php index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride all
          Require all granted
        </Directory>
          ''
      ];
    };
  };
}