Paul Martin
2016-04-30 a502d96a860456ec5e8c96761db70f7cabb74751
commit | author | age
8c99a7 1 ## Running Gitblit behind Apache
JM 2
9ef027 3 Gitblit runs fine behind Apache.
8c99a7 4
JM 5 Each Linux distribution may vary on the exact configuration of Apache 2.2.  
6 Here is a sample configuration that works on Debian 7.0 (Wheezy), your distribution may be different.
7
6c4be1 8 ### Make sure we have Apache's proxy modules
JM 9
10 ```
8c99a7 11 sudo su
JM 12 cd /etc/apache2/mods-enabled
13 ln -s ../mods-available/proxy.load proxy.load
14 ln -s ../mods-available/proxy_balancer.load proxy_balancer.load
15 ln -s ../mods-available/proxy_http.load proxy_http.load
6c4be1 16 ```
JM 17 ### Configuring Apache to use the proxy modules
18
19 Now we must configure Apache to use the proxy modules and  the proxied connection from Apache to Gitblit GO or from Apache to your chosen servlet container.  The following snippet is stored as `/etc/apache2/conf.d/gitblit`.  
20
21 ```
8c99a7 22 # Turn off support for true Proxy behaviour as we are acting as 
JM 23 # a transparent proxy
24 ProxyRequests Off
25
26 # Turn off VIA header as we know where the requests are proxied
27 ProxyVia Off
28  
29 # Turn on Host header preservation so that the servlet container
30 # can write links with the correct host and rewriting can be avoided.
31 #
32 # This is important for all git push/pull/clone operations.
33 ProxyPreserveHost On
34  
35 # Set the permissions for the proxy
36 <Proxy>
37     AddDefaultCharset off
38     Order deny,allow
39     Allow from all
40 </Proxy>
41  
42 # The proxy context path must match the Gitblit context path.
43 # For Gitblit GO, see server.contextPath in gitblit.properties.
44
45 #ProxyPass /gitblit http://localhost:8080/gitblit
46 #ProxyPassreverse /gitblit http://localhost:8080/gitblit
47
48 # If your httpd frontend is https but you are proxying http Gitblit WAR or GO
5f3ea6 49 #Header edit Location ^http://([^/]+)/gitblit/ https://$1/gitblit/
8c99a7 50
JM 51 # Additionally you will want to tell Gitblit the original scheme and port
52 #RequestHeader set X-Forwarded-Proto https
53 #RequestHeader set X-Forwarded-Port 443
54
55 # If you are using subdomain proxying then you will want to tell Gitblit the appropriate
56 # context path for your repository url.
57 # If you are not using subdomain proxying, then ignore this setting.
58 #RequestHeader set X-Forwarded-Context /
6c4be1 59 ```
JM 60
8c99a7 61 **Please** make sure to:  
JM 62     1. Review the security of these settings as appropriate for your deployment
9ef027 63     2. Uncomment the *ProxyPass* setting
8c99a7 64     3. Correctly set the ports and context paths both in the *ProxyPass* definition and your Gitblit installation  
JM 65     4. Set *web.mountParameters=false* in `gitblit.properties` or `web.xml` this will use parameterized URLs.  
66     Alternatively, you can respecify *web.forwardSlashCharacter*.
67
cc0477 68 ### Controlling Advertised Repository URLs
JM 69
70 In some reverse-proxy configurations you may be running Gitblit using an http interface with an https reverse-proxy proxy.  This will lead to Gitblit generating incorrect repository urls.
71
72 You can control the url that Gitblit generates by setting X-Forwarded headers in your proxy server.
73
74 *X-Forwarded-Proto*://servername(:*X-Forwarded-Port*)(/*X-Forwarded-Context*)
75
76 ---X:MEDIAWIKI---
77 {| class="table table-bordered"
78 ! Header
79 ! Description
80 |-
81 | X-Forwarded-Port
82 | The port to use in generated repository http/https urls
83 |-
84 | X-Forwarded-Proto
85 | The protocol/scheme to use in generated repository http/https urls
86 |-
87 | X-Forwarded-Context
88 | The context to use in generated repository http/https urls
89 |}
90 ---X:MEDIAWIKI---
91