blob: 3a9bcc749ce5995ed7f3d123a15e672bd4ab95c8 [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
Sven Selberg21585eb2020-08-28 13:30:04 +020024== Reverse proxy and client IPs
25
26When behind a reverse proxy the http_log will log the IP of the reverse proxy
27as client.ip. To log the correct client IP you must provide the
28'X-Forwarded-For' header from the reverse proxy.
29See the nginx configuration example below.
30
Francois Marier624f4472011-04-13 15:58:14 +120031
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080032== Apache 2 Configuration
Francois Marier624f4472011-04-13 15:58:14 +120033
Steffen Gebert832014f2013-06-03 21:42:47 +020034To run Gerrit behind an Apache server using 'mod_proxy', enable the
Francois Marier624f4472011-04-13 15:58:14 +120035necessary Apache2 modules:
36
37----
Steffen Gebert832014f2013-06-03 21:42:47 +020038 a2enmod proxy_http
Francois Marier624f4472011-04-13 15:58:14 +120039 a2enmod ssl ; # optional, needed for HTTPS / SSL
40----
41
Steffen Gebert832014f2013-06-03 21:42:47 +020042Configure an Apache VirtualHost to proxy to the Gerrit daemon,
43setting the 'ProxyPass' line to use the 'http://' URL configured
44above. Ensure the path of ProxyPass and httpd.listenUrl match,
45or links will redirect to incorrect locations.
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -080046
47----
48 <VirtualHost *>
49 ServerName review.example.com
50
Steffen Gebert832014f2013-06-03 21:42:47 +020051 ProxyRequests Off
52 ProxyVia Off
53 ProxyPreserveHost On
54
55 <Proxy *>
56 Order deny,allow
57 Allow from all
Conley Owens3c5d9ca2015-04-27 10:40:30 -070058 # Use following line instead of the previous two on Apache >= 2.4
59 # Require all granted
Steffen Gebert832014f2013-06-03 21:42:47 +020060 </Proxy>
61
62 AllowEncodedSlashes On
63 ProxyPass /r/ http://127.0.0.1:8081/r/ nocanon
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -080064 </VirtualHost>
65----
66
Steffen Gebert832014f2013-06-03 21:42:47 +020067The two options 'AllowEncodedSlashes On' and 'ProxyPass .. nocanon' are required
68since Gerrit 2.6.
69
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080070=== SSL
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -080071
72To enable Apache to perform the SSL processing, use 'proxy-https://'
73in httpd.listenUrl within Gerrit's configuration file, and enable
74the SSL engine in the Apache VirtualHost block:
75
76----
77 <VirtualHost *:443>
78 SSLEngine on
79 SSLCertificateFile conf/server.crt
80 SSLCertificateKeyFile conf/server.key
81
82 ... same as above ...
83 </VirtualHost>
84----
85
86See the Apache 'mod_ssl' documentation for more details on how to
87configure SSL within the server, like controlling how strong of an
88encryption algorithm is required.
89
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080090=== Troubleshooting
Steffen Gebert832014f2013-06-03 21:42:47 +020091
92If you are encountering 'Page Not Found' errors when opening the change
93screen, your Apache proxy is very likely decoding the passed URL.
94Make sure to either use 'AllowEncodedSlashes On' together with
Edwin Kempin1cdebf42015-05-05 15:58:51 +020095'ProxyPass .. nocanon' or alternatively a 'mod_rewrite' configuration with
Steffen Gebert832014f2013-06-03 21:42:47 +020096'AllowEncodedSlashes NoDecode' set.
97
Francois Marier624f4472011-04-13 15:58:14 +120098
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080099== Nginx Configuration
Francois Marier624f4472011-04-13 15:58:14 +1200100
101To run Gerrit behind an Nginx server, use a server statement such
102as this one:
103
104----
105 server {
106 listen 80;
Piotr Sikora2e6a4ae2011-04-13 17:11:18 +0000107 server_name review.example.com;
Francois Marier624f4472011-04-13 15:58:14 +1200108
Dariusz Lukszad5c33762015-06-26 09:15:51 +0200109 location ^~ /r/ {
Piotr Sikora2e6a4ae2011-04-13 17:11:18 +0000110 proxy_pass http://127.0.0.1:8081;
111 proxy_set_header X-Forwarded-For $remote_addr;
112 proxy_set_header Host $host;
Francois Marier624f4472011-04-13 15:58:14 +1200113 }
114 }
115----
116
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800117=== SSL
Francois Marier624f4472011-04-13 15:58:14 +1200118
119To enable Nginx to perform the SSL processing, use 'proxy-https://'
120in httpd.listenUrl within Gerrit's configuration file, and enable
121the SSL engine in the Nginx server statement:
122
123----
124 server {
125 listen 443;
Piotr Sikora2e6a4ae2011-04-13 17:11:18 +0000126 server_name review.example.com;
Francois Marier624f4472011-04-13 15:58:14 +1200127
128 ssl on;
129 ssl_certificate conf/server.crt;
130 ssl_certificate_key conf/server.key;
131
132 ... same as above ...
133 }
134----
135
136See the Nginx 'http ssl module' documentation for more details on
137how to configure SSL within the server, like controlling how strong
138of an encryption algorithm is required.
139
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800140=== Troubleshooting
Steffen Gebert832014f2013-06-03 21:42:47 +0200141
142If you are encountering 'Page Not Found' errors when opening the change
143screen, your Nginx proxy is very likely decoding the passed URL.
144Make sure to use a 'proxy_pass' URL without any path (esp. no trailing
145'/' after the 'host:port').
146
David Ostrovsky2aa67252014-06-05 08:36:16 +0200147If you are using Apache httpd server with mod_jk and AJP connector, add
148the following option to your httpd.conf directly or included from another
149file:
150
151----
152JkOptions +ForwardURICompatUnparsed
153----
154
Shawn O. Pearce9ad8ba52009-12-11 19:06:21 -0800155GERRIT
156------
157Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700158
159SEARCHBOX
160---------