-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp-httpd.conf
More file actions
112 lines (99 loc) · 5.97 KB
/
Copy pathapp-httpd.conf
File metadata and controls
112 lines (99 loc) · 5.97 KB
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
<VirtualHost *:8080>
AllowEncodedSlashes NoDecode
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule include_module modules/mod_include.so
LoadModule info_module modules/mod_info.so
DocumentRoot /usr/local/apache2/htdocs/gridstudy/
<Directory /usr/local/apache2/htdocs/gridstudy/>
<Files "index.html">
SetOutputFilter INCLUDES
</Files>
<FilesMatch "^(env\.json|idpSettings\.json)$">
# FileETag Digest for stable Etags accross loadbalanced servers for mounted files.
# "FileETag Digest" is acceptable here because these are only small files so
# having to read the full content of the file instead of just the filesystem
# metadata is not prohibitedly expensive. A better alternative would be to find
# a way to have stable filesystem metadata on all servers because:
# - accessing file system metadata is a lot less expensive.
# - contrary to apache httpd, nginx doesn't have an option to change the ETag
# generation method and always uses the filesystem metadata (size, mtime),
# so using "FileEtag Digest" locks us in with apache httpd.
# NOTE: this doesn't apply to files in the image (their filesystem metadata
# is the same because it's from the image), only to mounted files (bind mount
# or volume mount in docker compose, configmap in kubernetes)
# NOTE2: Because we use single file bind mounts for our files, the contents
# and filesystem metadata of our files fall out of sync between the host and
# the containers when the file is deleted or replaced (more precisely, as
# soon as the inode number of the file changes) (this can happen quite silently
# if your editor replaces the file when saving), but this means using Digest doesn't
# solve this issue. This is a known docker limitation: https://github.com/moby/moby/issues/6011
FileETag Digest
</FilesMatch>
Options +Includes
Header set Cache-Control "no-cache"
</Directory>
<Directory /usr/local/apache2/htdocs/gridstudy/assets/>
# All files in this folder are public and have in their name
# the hash of their content, so cache them very aggressively
# as per recommended best practices
# NOTE: coincidentally, this moves us out of a nasty apache bug
# where etags don't work at all with mod_deflate and apache never
# sends 304 for its own etags (304 only when manually removing the
# extra "-gzip" etag suffix). See
# https://bz.apache.org/bugzilla/show_bug.cgi?id=45023
Header set Cache-Control "public, max-age=31536000, immutable"
</Directory>
<Location "/actuator/info">
SetHandler server-info
</Location>
AddModuleInfo mod_info.c 'Hostname: ${HOSTNAME}'
# BEGIN Rewrite engine for SPA behavior and reverse proxy
RewriteEngine On
# helper definition to compute how many slashes we saw in the routed http request
# which is then set with SSI to the html base in index.html. This allows
# hosting the app at any path (e.g. not just at the root of a domain),
# and from the same deployment config (no base url hardcoded in the deployment),
# while still allowing the javascript client app routing to know which part of the path
# to use for javascript routing, versus which path of the path is used for hosting routing.
# Example:
# browser sends mydomain.com/myapp1/foo/bar/baz
# hosting routing strips mydomain.com/myapp1 and sends /foo/bar/baz to this server
# this server replies with <base="../.."> in index.html
# browser recovers the base using "../.." from the original url mydomain.com/myapp1/foo/bar/baz
# => hosting at mydomain.com/myapp1/
# => client route foo/bar/baz
# The computed base is "." or ".." or "../.." or "../../.." and so on
RewriteMap remapbase "prg:/bin/sed -u -e 's;[^ ]* ;;' -e 's;[ ?].*;;' -e 's;[^/]*;..;g' -e 's;../..;;' -e 's/.//' -e 's;^$;.;'"
# For files (e.g. our css and javascript) or reverse proxied urls,
# skip the classic SPA "rewrite everything to /index.html"
RewriteCond /usr/local/apache2/htdocs/gridstudy%{REQUEST_URI} -f [OR]
RewriteCond %{REQUEST_URI} ^/api/.* [OR]
RewriteCond %{REQUEST_URI} ^/ws/.*
RewriteRule ^ - [S=2]
# We (ab)use a RewriteRule just to run the external computation of the base
# and temporarily store the result in place of the request (it doesn't matter
# as the request is always replaced with /index.html in the end anyway).
# We must store it in place of the request because it will allow the next RewriteRule
# to capture it and set it with the E flag in a variable for SSI to use
RewriteRule ^ "${remapbase:%{THE_REQUEST}}" [DPI]
# Note here for the slash in the pattern, it's because somewhere between
# 2.4.55 and 2.4.68, rewrite_mod started to add a leading slash to our
# computed base, as seen in the following logs
# mod_rewrite.c: rewrite '/' -> '.'
# mod_rewrite.c: add root prefix: . -> /.
# so we capture everything except the the leading slash in the pattern
# make it optional to hopefully improve resilience, this pattern must always
# match to respond with the html for our SPA to work !
RewriteRule "^/?(.*)$" /index.html [E=BASE:$1,L]
# Needed if the request is directly index.html, the file exists and the rules are skipped
# and base is not set so we set it here if unset
SetEnvIf BASE ^$ BASE=.
# END Rewrite engine for SPA behavior and reverse proxy
ProxyRequests off
ProxyPassMatch "^/api/gateway/(.*)$" http://gateway/$1 nocanon
ProxyPassMatch "^/ws/gateway/(.*)$" ws://gateway/$1 nocanon
LimitRequestLine 64000
</VirtualHost>