Bug 36531: Serve text/javascript compressed, like application/javascript is
[koha.git] / etc / koha-httpd.conf
1 # Koha Apache Configuration Directives
2
3 #NameVirtualHost *
4
5 ## OPAC
6 <VirtualHost __WEBSERVER_IP__:__WEBSERVER_PORT__>
7    ServerAdmin  __WEBMASTER_EMAIL__
8    DocumentRoot __OPAC_WWW_DIR__
9    ServerName __WEBSERVER_HOST__
10 #  ServerAlias opac.mydomain.com
11    ScriptAlias /cgi-bin/koha/ "__OPAC_CGI_DIR__/opac/"
12    ScriptAlias /index.html "__OPAC_CGI_DIR__/opac/opac-main.pl"
13    ScriptAlias /opac-search.pl "__OPAC_CGI_DIR__/opac/opac-search.pl"
14    ScriptAlias /search "__OPAC_CGI_DIR__/opac/opac-search.pl"
15    ErrorLog __LOG_DIR__/koha-opac-error_log
16 #  CustomLog __LOG_DIR__/koha-opac-access.log combined
17 #  TransferLog __LOG_DIR__/koha-opac-access.log
18    SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"
19    SetEnv PERL5LIB "__PERL5LIB_DIRS__"
20
21    # This syntax allows you to override a system preference
22    # for a given virtual host. Use with caution!
23    # You should add all the system preferences you override
24    # in one or more vhosts to the environment variable
25    # OVERRIDE_SYSPREF_NAMES for your staff intranet vhost
26    # SetEnv OVERRIDE_SYSPREF_PrefName Value
27
28    <Directory "__OPAC_WWW_DIR__">
29       Options -Indexes
30    </Directory>
31
32    # Secure internal stuff
33    <DirectoryMatch "__OPAC_WWW_DIR__/.*/(modules|xslt|includes)">
34       Require all denied
35    </DirectoryMatch>
36
37    <IfModule mod_gzip.c>
38      mod_gzip_on yes
39      mod_gzip_dechunk yes
40      mod_gzip_keep_workfiles No
41      mod_gzip_can_negotiate yes
42      mod_gzip_update_static No
43      mod_gzip_temp_dir /tmp
44      mod_gzip_minimum_file_size 512
45      mod_gzip_maximum_file_size 1000000
46      mod_gzip_maximum_inmem_size 1000000
47      mod_gzip_handle_methods GET POST
48      mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
49      mod_gzip_item_exclude mime ^image/.*
50      mod_gzip_item_exclude rspheader Content-Type:image/*
51      mod_gzip_item_include file \.js$
52      mod_gzip_item_include mime ^application/javascript$
53      mod_gzip_item_include mime ^text/javascript$
54      mod_gzip_item_include mime ^application/x-javascript$
55      mod_gzip_item_include file \.php$
56      mod_gzip_item_include mime ^text/html$
57      mod_gzip_item_include file \.css$
58      mod_gzip_item_include mime ^text/css$
59   </IfModule>
60
61   <IfModule mod_deflate.c>
62
63     # Compress content with type html, text, and css, ...
64     AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
65     AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
66     AddOutputFilterByType DEFLATE application/javascript text/javascript application/x-javascript application/json
67
68     DeflateCompressionLevel 9
69
70     # Properly handle old browsers that do not support compression
71     BrowserMatch ^Mozilla/4 gzip-only-text/html
72     BrowserMatch ^Mozilla/4\.0[678] no-gzip
73     BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
74
75     DeflateFilterNote Input instream
76     DeflateFilterNote Output outstream
77     DeflateFilterNote Ratio ratio
78
79     LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
80     <IfModule mod_headers.c>
81        #properly handle requests coming from behind proxies
82        Header append Vary User-Agent
83     </IfModule>
84   </IfModule>
85
86
87 #  Repeat this virtualhost stanza changing the following environment vars to
88 #  create multiple OPAC interfaces with custom css and/or search limits:
89 #  SetEnv OPAC_CSS_OVERRIDE mystyle.css
90 #  SetEnv OPAC_SEARCH_LIMIT branch:CODE
91 #  SetEnv OPAC_LIMIT_OVERRIDE 1
92
93    Options +FollowSymLinks
94
95    ErrorDocument 400 /cgi-bin/koha/errors/400.pl
96    ErrorDocument 401 /cgi-bin/koha/errors/401.pl
97    ErrorDocument 403 /cgi-bin/koha/errors/403.pl
98    ErrorDocument 404 /cgi-bin/koha/errors/404.pl
99    ErrorDocument 500 /cgi-bin/koha/errors/500.pl
100
101    <IfModule mod_rewrite.c>
102      # Rewrite Rules
103      RewriteEngine On
104
105      RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/opac-detail\.pl?bib=$1 [PT]
106      RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT]
107      RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT]
108      RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L]
109
110      RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT]
111
112      # REST API configuration
113      Alias "/api" "__API_CGI_DIR__"
114      <Directory __API_CGI_DIR__>
115        Options +ExecCGI +FollowSymlinks
116        AddHandler cgi-script .pl
117
118        SetEnv MOJO_MODE "production"
119
120        RewriteEngine On
121        RewriteBase /api/
122        RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl
123        RewriteRule ^(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L]
124
125      </Directory>
126    </IfModule>
127
128    <IfModule mod_expires.c>
129       ExpiresActive on
130       ExpiresByType text/css "access plus 60 days"
131       ExpiresByType application/javascript "access plus 60 days"
132       ExpiresByType image/png "access plus 12 hours"
133       ExpiresByType image/gif "access plus 12 hours"
134    </IfModule>
135 </VirtualHost>
136
137 ## Intranet
138 <VirtualHost __WEBSERVER_IP__:__WEBSERVER_PORT_LIBRARIAN__>
139    ServerAdmin __WEBMASTER_EMAIL__
140    DocumentRoot __INTRANET_WWW_DIR__
141    ServerName __WEBSERVER_HOST__:__WEBSERVER_PORT_LIBRARIAN__
142 #  ServerAlias intranet.mydomain.com
143    ScriptAlias /cgi-bin/koha/ "__INTRANET_CGI_DIR__/"
144    ScriptAlias /index.html "__INTRANET_CGI_DIR__/mainpage.pl"
145    ScriptAlias /search "__INTRANET_CGI_DIR__/catalogue/search.pl"
146    Alias /plugin/ "__PLUGINS_DIR__/"
147    ErrorLog __LOG_DIR__/koha-error_log
148 #  TransferLog __LOG_DIR__/koha-access.log
149    SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"
150    SetEnv PERL5LIB "__PERL5LIB_DIRS__"
151    Options +FollowSymLinks
152
153    # If you are overriding any system preferences,
154    # list them in this variable so the preference editor
155    # knows that they have been overridden.
156    # SetEnv OVERRIDE_SYSPREF_NAMES "Pref1,Pref2,Pref3"
157
158    ErrorDocument 400 /cgi-bin/koha/errors/400.pl
159    ErrorDocument 401 /cgi-bin/koha/errors/401.pl
160    ErrorDocument 403 /cgi-bin/koha/errors/403.pl
161    ErrorDocument 404 /cgi-bin/koha/errors/404.pl
162    ErrorDocument 500 /cgi-bin/koha/errors/500.pl
163
164    <Directory "__INTRANET_WWW_DIR__">
165       Options -Indexes
166    </Directory>
167
168    # Secure internal stuff
169    <DirectoryMatch "__INTRANET_WWW_DIR__/.*/(modules|xslt|includes)">
170       Require all denied
171       <FilesMatch "\.(json)$">
172         Require all granted
173       </FilesMatch>
174    </DirectoryMatch>
175
176    <IfModule mod_gzip.c>
177      mod_gzip_on yes
178      mod_gzip_dechunk yes
179      mod_gzip_keep_workfiles No
180      mod_gzip_can_negotiate yes
181      mod_gzip_update_static No
182      mod_gzip_temp_dir /tmp
183      mod_gzip_minimum_file_size 512
184      mod_gzip_maximum_file_size 1000000
185      mod_gzip_maximum_inmem_size 1000000
186      mod_gzip_handle_methods GET POST
187      mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
188      mod_gzip_item_exclude mime ^image/.*
189      mod_gzip_item_exclude rspheader Content-Type:image/*
190      mod_gzip_item_include file \.js$
191      mod_gzip_item_include mime ^application/javascript$
192      mod_gzip_item_include mime ^text/javascript$
193      mod_gzip_item_include mime ^application/x-javascript$
194      mod_gzip_item_include file \.php$
195      mod_gzip_item_include mime ^text/html$
196      mod_gzip_item_include file \.css$
197      mod_gzip_item_include mime ^text/css$
198    </IfModule>
199
200    <IfModule mod_deflate.c>
201
202      # Compress content with type html, text, and css, ...
203      AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
204      AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
205      AddOutputFilterByType DEFLATE application/javascript text/javascript application/x-javascript application/json
206
207      DeflateCompressionLevel 9
208
209      # Properly handle old browsers that do not support compression
210      BrowserMatch ^Mozilla/4 gzip-only-text/html
211      BrowserMatch ^Mozilla/4\.0[678] no-gzip
212      BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
213
214      DeflateFilterNote Input instream
215      DeflateFilterNote Output outstream
216      DeflateFilterNote Ratio ratio
217
218      LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
219      <IfModule mod_headers.c>
220        #properly handle requests coming from behind proxies
221        Header append Vary User-Agent
222      </IfModule>
223   </IfModule>
224
225    <IfModule mod_rewrite.c>
226      # Rewrite Rules
227      RewriteEngine On
228
229      RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/catalogue/detail.pl?biblionumber=$1 [PT]
230      RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT]
231      RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT]
232      RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L]
233
234
235      # REST API configuration
236      Alias "/api" "__API_CGI_DIR__"
237      <Directory __API_CGI_DIR__>
238        Options +ExecCGI +FollowSymlinks
239        AddHandler cgi-script .pl
240
241        SetEnv MOJO_MODE "production"
242
243        RewriteEngine On
244        RewriteBase /api/
245        RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl
246        RewriteRule ^(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L]
247      </Directory>
248    </IfModule>
249
250    <IfModule mod_expires.c>
251       ExpiresActive on
252       ExpiresByType text/css "access plus 60 days"
253       ExpiresByType application/javascript "access plus 60 days"
254       ExpiresByType image/png "access plus 12 hours"
255       ExpiresByType image/gif "access plus 12 hours"
256    </IfModule>
257 </VirtualHost>
258
259 # Uncomment this VirtualHost to enable API access through
260 # api.__WEBSERVER_HOST__:__WEBSERVER_PORT__
261 #<VirtualHost __WEBSERVER_IP__:__WEBSERVER_PORT__>
262 #  ServerAdmin __WEBMASTER_EMAIL__
263 #  DocumentRoot __INTRANET_CGI_DIR__/api
264 #  ServerName api.__WEBSERVER_HOST__:__WEBSERVER_PORT__
265 #  SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"
266 #  SetEnv PERL5LIB "__PERL5LIB_DIRS__"
267 #  ErrorLog __LOG_DIR__/koha-api-error_log
268 #
269 #  <IfModule mod_rewrite.c>
270 #    <Directory __API_CGI_DIR__>
271 #      Options +ExecCGI +FollowSymlinks
272 #      AddHandler cgi-script .pl
273 #
274 #      SetEnv MOJO_MODE "production"
275 #
276 #      RewriteEngine on
277 #
278 #      RewriteRule ^api/(.*) $1 [L]
279 #
280 #      RewriteCond %{REQUEST_FILENAME} !-f
281 #      RewriteCond %{REQUEST_FILENAME} !-d
282 #      RewriteCond %{DOCUMENT_ROOT}/$1/app.pl -f
283 #      RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L]
284 #    </Directory>
285 #  </IfModule>
286 #</VirtualHost>