aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/immae/production.nix
blob: 8b4998f39c42df7de04fed3539e33cce495433cb (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{ lib, pkgs, config,  ... }:
let
  cfg = config.myServices.websites.immae.production;
  varDir = "/var/lib/buildbot/outputs/immae/blog";
  coursDir = "/var/lib/buildbot/outputs/immae/cours";
  rechercheDir = "/var/lib/buildbot/outputs/immae/recherche";
  recettesDir = "/var/lib/buildbot/outputs/immae/recettes";
  historyDir = "/var/lib/buildbot/outputs/immae/history";
  docsDir = "/var/lib/buildbot/outputs/immae/docs/";
  env = config.myEnv.websites.immae;
in {
  options.myServices.websites.immae.production.enable = lib.mkEnableOption "enable Immae's website";

  config = lib.mkIf cfg.enable {
    services.webstats.sites = [ { name = "www.immae.eu"; } ];

    services.websites.env.production.vhostConfs.immae_production = {
      certName     = "immae";
      addToCerts   = true;
      certMainHost = "www.immae.eu";
      hosts        = [ "www.immae.eu" "immae.eu" ];
      root         = varDir;
      extraConfig  = [
        ''
        Use Stats www.immae.eu
        Header always set Strict-Transport-Security "max-age=31536000"

        <LocationMatch /.well-known/(webfinger|host-meta)>
          Header always set Referrer-Policy "strict-origin-when-cross-origin"
          RequestHeader set X-Forwarded-Proto "https"

          RewriteRule ^(.*)$ https://mastodon.immae.eu%{REQUEST_URI} [QSA,L]
        </LocationMatch>

        RewriteEngine On
        RewriteCond "%{REQUEST_URI}" "!^/.well-known/(webfinger|host-meta)"
        RewriteCond "%{HTTP_HOST}" "!^www\.immae\.eu$" [NC]
        RewriteRule ^(.+)$ https://www.immae.eu$1 [R=302,L]

        <Directory ${varDir}>
          DirectoryIndex index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
        </Directory>

        Alias /.well-known/chatonsinfos ${./chatons}
        <Directory ${./chatons}>
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride None
          Require all granted
        </Directory>

        Alias /.well-known/matrix ${./matrix}
        <Directory ${./matrix}>
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride None
          Require all granted
          Header always set Access-Control-Allow-Origin "*"
        </Directory>

        Alias /cours ${coursDir}
        <Directory ${coursDir}>
          DirectoryIndex index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
        </Directory>

        Alias /docs ${docsDir}
        <Directory ${docsDir}>
          DirectoryIndex index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
        </Directory>

        Alias /eurl ${./eurl}
        <Directory ${./eurl}>
          DirectoryIndex index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride None
          Require all granted
        </Directory>

        Alias /recherche ${rechercheDir}
        <Directory ${rechercheDir}>
          DirectoryIndex index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
        </Directory>

        Alias /recettes ${recettesDir}
        <Directory ${recettesDir}>
          DirectoryIndex index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
        </Directory>

        Alias /history ${historyDir}
        <Directory ${historyDir}>
          DirectoryIndex index.html
          AllowOverride None
          Require all granted
        </Directory>
        ''
      ];
    };

    services.websites.env.production.vhostConfs.immae_fr = {
      certName    = "immae";
      addToCerts  = true;
      hosts       = [ "www.immae.fr" "immae.fr" ];
      root        = null;
      extraConfig = [ ''
        RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://www.immae.eu/chapeaux/
        '' ];
    };

    services.websites.env.production.vhostConfs.immae_bouya = {
      certName    = "immae";
      addToCerts  = true;
      hosts       = [ "bouya.org" "www.bouya.org" ];
      root        = rechercheDir;
      extraConfig = [ ''
        <Directory ${rechercheDir}>
          DirectoryIndex index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
        </Directory>
        '' ];
    };
  };
}