blob: eff777bce97b019f767de0ba122717fd73960873 [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= Gerrit Code Review - Reverse Proxy
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -08002
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08003== Description
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -08004
Francois Marier624f4472011-04-13 15:58:14 +12005Gerrit can be configured to run behind a third-party web server.
David Pursehouse221d4f62012-06-08 17:38:08 +09006This allows the other web server to bind to the privileged port 80
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -08007(or 443 for SSL), as well as offloads the SSL processing overhead
8from Java to optimized native C code.
9
10
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080011== Gerrit Configuration
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -080012
13Ensure `'$site_path'/etc/gerrit.config` has the property
14link:config-gerrit.html#httpd.listenUrl[httpd.listenUrl] configured
15to use 'proxy-http://' or 'proxy-https://' and a free port number.
16This may have already been configured if proxy support was enabled
17during 'init'.
18
19----
20 [httpd]
21 listenUrl = proxy-http://127.0.0.1:8081/r/
22----
23
Francois Marier624f4472011-04-13 15:58:14 +120024
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080025== Apache 2 Configuration
Francois Marier624f4472011-04-13 15:58:14 +120026
Steffen Gebert832014f2013-06-03 21:42:47 +020027To run Gerrit behind an Apache server using 'mod_proxy', enable the
Francois Marier624f4472011-04-13 15:58:14 +120028necessary Apache2 modules:
29
30----
Steffen Gebert832014f2013-06-03 21:42:47 +020031 a2enmod proxy_http
Francois Marier624f4472011-04-13 15:58:14 +120032 a2enmod ssl ; # optional, needed for HTTPS / SSL
33----
34
Steffen Gebert832014f2013-06-03 21:42:47 +020035Configure an Apache VirtualHost to proxy to the Gerrit daemon,
36setting the 'ProxyPass' line to use the 'http://' URL configured
37above. Ensure the path of ProxyPass and httpd.listenUrl match,
38or links will redirect to incorrect locations.
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -080039
40----
41 <VirtualHost *>
42 ServerName review.example.com
43
Steffen Gebert832014f2013-06-03 21:42:47 +020044 ProxyRequests Off
45 ProxyVia Off
46 ProxyPreserveHost On
47
48 <Proxy *>
49 Order deny,allow
50 Allow from all
Conley Owens3c5d9ca2015-04-27 10:40:30 -070051 # Use following line instead of the previous two on Apache >= 2.4
52 # Require all granted
Steffen Gebert832014f2013-06-03 21:42:47 +020053 </Proxy>
54
55 AllowEncodedSlashes On
56 ProxyPass /r/ http://127.0.0.1:8081/r/ nocanon
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -080057 </VirtualHost>
58----
59
Steffen Gebert832014f2013-06-03 21:42:47 +020060The two options 'AllowEncodedSlashes On' and 'ProxyPass .. nocanon' are required
61since Gerrit 2.6.
62
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080063=== SSL
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -080064
65To enable Apache to perform the SSL processing, use 'proxy-https://'
66in httpd.listenUrl within Gerrit's configuration file, and enable
67the SSL engine in the Apache VirtualHost block:
68
69----
70 <VirtualHost *:443>
71 SSLEngine on
72 SSLCertificateFile conf/server.crt
73 SSLCertificateKeyFile conf/server.key
74
75 ... same as above ...
76 </VirtualHost>
77----
78
79See the Apache 'mod_ssl' documentation for more details on how to
80configure SSL within the server, like controlling how strong of an
81encryption algorithm is required.
82
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080083=== Troubleshooting
Steffen Gebert832014f2013-06-03 21:42:47 +020084
85If you are encountering 'Page Not Found' errors when opening the change
86screen, your Apache proxy is very likely decoding the passed URL.
87Make sure to either use 'AllowEncodedSlashes On' together with
Edwin Kempin1cdebf42015-05-05 15:58:51 +020088'ProxyPass .. nocanon' or alternatively a 'mod_rewrite' configuration with
Steffen Gebert832014f2013-06-03 21:42:47 +020089'AllowEncodedSlashes NoDecode' set.
90
Francois Marier624f4472011-04-13 15:58:14 +120091
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080092== Nginx Configuration
Francois Marier624f4472011-04-13 15:58:14 +120093
94To run Gerrit behind an Nginx server, use a server statement such
95as this one:
96
97----
98 server {
99 listen 80;
Piotr Sikora2e6a4ae2011-04-13 17:11:18 +0000100 server_name review.example.com;
Francois Marier624f4472011-04-13 15:58:14 +1200101
Dariusz Lukszad5c33762015-06-26 09:15:51 +0200102 location ^~ /r/ {
Piotr Sikora2e6a4ae2011-04-13 17:11:18 +0000103 proxy_pass http://127.0.0.1:8081;
104 proxy_set_header X-Forwarded-For $remote_addr;
105 proxy_set_header Host $host;
Francois Marier624f4472011-04-13 15:58:14 +1200106 }
107 }
108----
109
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800110=== SSL
Francois Marier624f4472011-04-13 15:58:14 +1200111
112To enable Nginx to perform the SSL processing, use 'proxy-https://'
113in httpd.listenUrl within Gerrit's configuration file, and enable
114the SSL engine in the Nginx server statement:
115
116----
117 server {
118 listen 443;
Piotr Sikora2e6a4ae2011-04-13 17:11:18 +0000119 server_name review.example.com;
Francois Marier624f4472011-04-13 15:58:14 +1200120
121 ssl on;
122 ssl_certificate conf/server.crt;
123 ssl_certificate_key conf/server.key;
124
125 ... same as above ...
126 }
127----
128
129See the Nginx 'http ssl module' documentation for more details on
130how to configure SSL within the server, like controlling how strong
131of an encryption algorithm is required.
132
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800133=== Troubleshooting
Steffen Gebert832014f2013-06-03 21:42:47 +0200134
135If you are encountering 'Page Not Found' errors when opening the change
136screen, your Nginx proxy is very likely decoding the passed URL.
137Make sure to use a 'proxy_pass' URL without any path (esp. no trailing
138'/' after the 'host:port').
139
David Ostrovsky2aa67252014-06-05 08:36:16 +0200140If you are using Apache httpd server with mod_jk and AJP connector, add
141the following option to your httpd.conf directly or included from another
142file:
143
144----
145JkOptions +ForwardURICompatUnparsed
146----
147
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -0800148GERRIT
149------
150Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700151
152SEARCHBOX
153---------