Florian Zschocke
2013-07-09 a0c34e37fe8e456a21c7a57e9d45e637ab40cce8
commit | author | age
8c99a7 1 ## Running Gitblit behind Apache
JM 2
3 Gitblit runs fine behind Apache.  You may use either *mod_proxy* (GO or WAR) or *mod_proxy_ajp* (GO).
4
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
8 1. First we need to make sure we have Apache's proxy modules available.  
9 ---FIXED---
10 sudo su
11 cd /etc/apache2/mods-enabled
12 ln -s ../mods-available/proxy.load proxy.load
13 ln -s ../mods-available/proxy_balancer.load proxy_balancer.load
14 ln -s ../mods-available/proxy_http.load proxy_http.load
15 ln -s ../mods-available/proxy_ajp.load proxy_ajp.load
16 ---FIXED---
17 2. Then we need to make sure we are configuring Apache to use the proxy modules and to setup 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`.  
18 ---FIXED---
19 # Turn off support for true Proxy behaviour as we are acting as 
20 # a transparent proxy
21 ProxyRequests Off
22
23 # Turn off VIA header as we know where the requests are proxied
24 ProxyVia Off
25  
26 # Turn on Host header preservation so that the servlet container
27 # can write links with the correct host and rewriting can be avoided.
28 #
29 # This is important for all git push/pull/clone operations.
30 ProxyPreserveHost On
31  
32 # Set the permissions for the proxy
33 <Proxy>
34     AddDefaultCharset off
35     Order deny,allow
36     Allow from all
37 </Proxy>
38  
39 # The proxy context path must match the Gitblit context path.
40 # For Gitblit GO, see server.contextPath in gitblit.properties.
41
42 #ProxyPass /gitblit http://localhost:8080/gitblit
43 #ProxyPassreverse /gitblit http://localhost:8080/gitblit
44
45 # If your httpd frontend is https but you are proxying http Gitblit WAR or GO
46 #Header edit Location &#94;http://([&#94;&#8260;]+)/gitblit/ https://&#36;1/gitblit/
47
48 # Additionally you will want to tell Gitblit the original scheme and port
49 #RequestHeader set X-Forwarded-Proto https
50 #RequestHeader set X-Forwarded-Port 443
51
52 # If you are using subdomain proxying then you will want to tell Gitblit the appropriate
53 # context path for your repository url.
54 # If you are not using subdomain proxying, then ignore this setting.
55 #RequestHeader set X-Forwarded-Context /
56
57 #ProxyPass /gitblit ajp://localhost:8009/gitblit
58 ---FIXED---  
59 **Please** make sure to:  
60     1. Review the security of these settings as appropriate for your deployment
61     2. Uncomment the *ProxyPass* setting for whichever connection you prefer (http/ajp)
62     3. Correctly set the ports and context paths both in the *ProxyPass* definition and your Gitblit installation  
63     If you are using Gitblit GO you can easily configure the AJP connector by specifying a non-zero AJP port.  
64     Please remember that on Linux/UNIX, ports < 1024 require root permissions to open.
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