1{ config, pkgs, serverInfo, lib, ... }:
2
3let
4 extraWorkersProperties = lib.optionalString (config ? extraWorkersProperties) config.extraWorkersProperties;
5
6 workersProperties = pkgs.writeText "workers.properties" ''
7# Define list of workers that will be used
8# for mapping requests
9# The configuration directives are valid
10# for the mod_jk version 1.2.18 and later
11#
12worker.list=loadbalancer,status
13
14# Define Node1
15# modify the host as your host IP or DNS name.
16worker.node1.port=8009
17worker.node1.host=localhost
18worker.node1.type=ajp13
19worker.node1.lbfactor=1
20
21# Load-balancing behaviour
22worker.loadbalancer.type=lb
23worker.loadbalancer.balance_workers=node1
24
25# Status worker for managing load balancer
26worker.status.type=status
27
28${extraWorkersProperties}
29 '';
30in
31{
32
33 options = {
34 extraWorkersProperties = lib.mkOption {
35 default = "";
36 description = "Additional configuration for the workers.properties file.";
37 };
38 };
39
40 extraModules = [
41 { name = "jk"; path = "${pkgs.tomcat_connectors}/modules/mod_jk.so"; }
42 ];
43
44 extraConfig = ''
45# Where to find workers.properties
46JkWorkersFile ${workersProperties}
47
48# Where to put jk logs
49JkLogFile ${serverInfo.serverConfig.logDir}/mod_jk.log
50
51# Set the jk log level [debug/error/info]
52JkLogLevel info
53
54# Select the log format
55JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
56
57# JkOptions indicates to send SSK KEY SIZE
58# Note: Changed from +ForwardURICompat.
59# See http://tomcat.apache.org/security-jk.html
60JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
61
62# JkRequestLogFormat
63JkRequestLogFormat "%w %V %T"
64
65# Mount your applications
66JkMount /__application__/* loadbalancer
67
68# You can use external file for mount points.
69# It will be checked for updates each 60 seconds.
70# The format of the file is: /url=worker
71# /examples/*=loadbalancer
72#JkMountFile uriworkermap.properties
73
74# Add shared memory.
75# This directive is present with 1.2.10 and
76# later versions of mod_jk, and is needed for
77# for load balancing to work properly
78# Note: Replaced JkShmFile logs/jk.shm due to SELinux issues. Refer to
79# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=225452
80JkShmFile ${serverInfo.serverConfig.stateDir}/jk.shm
81
82# Static files in all Tomcat webapp context directories are served by apache
83JkAutoAlias /var/tomcat/webapps
84
85# All requests go to worker by default
86JkMount /* loadbalancer
87# Serve some static files using httpd
88#JkUnMount /*.html loadbalancer
89#JkUnMount /*.jpg loadbalancer
90#JkUnMount /*.gif loadbalancer
91#JkUnMount /*.css loadbalancer
92#JkUnMount /*.png loadbalancer
93#JkUnMount /*.js loadbalancer
94
95# Add jkstatus for managing runtime data
96<Location /jkstatus/>
97JkMount status
98Order deny,allow
99Deny from all
100Allow from 127.0.0.1
101</Location>
102 '';
103}