Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Reverse Proxy |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 2 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 3 | == Description |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 4 | |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 5 | Gerrit can be configured to run behind a third-party web server. |
David Pursehouse | 221d4f6 | 2012-06-08 17:38:08 +0900 | [diff] [blame] | 6 | This allows the other web server to bind to the privileged port 80 |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 7 | (or 443 for SSL), as well as offloads the SSL processing overhead |
| 8 | from Java to optimized native C code. |
| 9 | |
| 10 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 11 | == Gerrit Configuration |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 12 | |
| 13 | Ensure `'$site_path'/etc/gerrit.config` has the property |
| 14 | link:config-gerrit.html#httpd.listenUrl[httpd.listenUrl] configured |
| 15 | to use 'proxy-http://' or 'proxy-https://' and a free port number. |
| 16 | This may have already been configured if proxy support was enabled |
| 17 | during 'init'. |
| 18 | |
| 19 | ---- |
| 20 | [httpd] |
| 21 | listenUrl = proxy-http://127.0.0.1:8081/r/ |
| 22 | ---- |
| 23 | |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 24 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 25 | == Apache 2 Configuration |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 26 | |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 27 | To run Gerrit behind an Apache server using 'mod_proxy', enable the |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 28 | necessary Apache2 modules: |
| 29 | |
| 30 | ---- |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 31 | a2enmod proxy_http |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 32 | a2enmod ssl ; # optional, needed for HTTPS / SSL |
| 33 | ---- |
| 34 | |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 35 | Configure an Apache VirtualHost to proxy to the Gerrit daemon, |
| 36 | setting the 'ProxyPass' line to use the 'http://' URL configured |
| 37 | above. Ensure the path of ProxyPass and httpd.listenUrl match, |
| 38 | or links will redirect to incorrect locations. |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 39 | |
| 40 | ---- |
| 41 | <VirtualHost *> |
| 42 | ServerName review.example.com |
| 43 | |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 44 | ProxyRequests Off |
| 45 | ProxyVia Off |
| 46 | ProxyPreserveHost On |
| 47 | |
| 48 | <Proxy *> |
| 49 | Order deny,allow |
| 50 | Allow from all |
Conley Owens | 3c5d9ca | 2015-04-27 10:40:30 -0700 | [diff] [blame] | 51 | # Use following line instead of the previous two on Apache >= 2.4 |
| 52 | # Require all granted |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 53 | </Proxy> |
| 54 | |
| 55 | AllowEncodedSlashes On |
| 56 | ProxyPass /r/ http://127.0.0.1:8081/r/ nocanon |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 57 | </VirtualHost> |
| 58 | ---- |
| 59 | |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 60 | The two options 'AllowEncodedSlashes On' and 'ProxyPass .. nocanon' are required |
| 61 | since Gerrit 2.6. |
| 62 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 63 | === SSL |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 64 | |
| 65 | To enable Apache to perform the SSL processing, use 'proxy-https://' |
| 66 | in httpd.listenUrl within Gerrit's configuration file, and enable |
| 67 | the 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 | |
| 79 | See the Apache 'mod_ssl' documentation for more details on how to |
| 80 | configure SSL within the server, like controlling how strong of an |
| 81 | encryption algorithm is required. |
| 82 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 83 | === Troubleshooting |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 84 | |
| 85 | If you are encountering 'Page Not Found' errors when opening the change |
| 86 | screen, your Apache proxy is very likely decoding the passed URL. |
| 87 | Make sure to either use 'AllowEncodedSlashes On' together with |
Edwin Kempin | 1cdebf4 | 2015-05-05 15:58:51 +0200 | [diff] [blame] | 88 | 'ProxyPass .. nocanon' or alternatively a 'mod_rewrite' configuration with |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 89 | 'AllowEncodedSlashes NoDecode' set. |
| 90 | |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 91 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 92 | == Nginx Configuration |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 93 | |
| 94 | To run Gerrit behind an Nginx server, use a server statement such |
| 95 | as this one: |
| 96 | |
| 97 | ---- |
| 98 | server { |
| 99 | listen 80; |
Piotr Sikora | 2e6a4ae | 2011-04-13 17:11:18 +0000 | [diff] [blame] | 100 | server_name review.example.com; |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 101 | |
Dariusz Luksza | d5c3376 | 2015-06-26 09:15:51 +0200 | [diff] [blame] | 102 | location ^~ /r/ { |
Piotr Sikora | 2e6a4ae | 2011-04-13 17:11:18 +0000 | [diff] [blame] | 103 | proxy_pass http://127.0.0.1:8081; |
| 104 | proxy_set_header X-Forwarded-For $remote_addr; |
| 105 | proxy_set_header Host $host; |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | ---- |
| 109 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 110 | === SSL |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 111 | |
| 112 | To enable Nginx to perform the SSL processing, use 'proxy-https://' |
| 113 | in httpd.listenUrl within Gerrit's configuration file, and enable |
| 114 | the SSL engine in the Nginx server statement: |
| 115 | |
| 116 | ---- |
| 117 | server { |
| 118 | listen 443; |
Piotr Sikora | 2e6a4ae | 2011-04-13 17:11:18 +0000 | [diff] [blame] | 119 | server_name review.example.com; |
Francois Marier | 624f447 | 2011-04-13 15:58:14 +1200 | [diff] [blame] | 120 | |
| 121 | ssl on; |
| 122 | ssl_certificate conf/server.crt; |
| 123 | ssl_certificate_key conf/server.key; |
| 124 | |
| 125 | ... same as above ... |
| 126 | } |
| 127 | ---- |
| 128 | |
| 129 | See the Nginx 'http ssl module' documentation for more details on |
| 130 | how to configure SSL within the server, like controlling how strong |
| 131 | of an encryption algorithm is required. |
| 132 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 133 | === Troubleshooting |
Steffen Gebert | 832014f | 2013-06-03 21:42:47 +0200 | [diff] [blame] | 134 | |
| 135 | If you are encountering 'Page Not Found' errors when opening the change |
| 136 | screen, your Nginx proxy is very likely decoding the passed URL. |
| 137 | Make sure to use a 'proxy_pass' URL without any path (esp. no trailing |
| 138 | '/' after the 'host:port'). |
| 139 | |
David Ostrovsky | 2aa6725 | 2014-06-05 08:36:16 +0200 | [diff] [blame] | 140 | If you are using Apache httpd server with mod_jk and AJP connector, add |
| 141 | the following option to your httpd.conf directly or included from another |
| 142 | file: |
| 143 | |
| 144 | ---- |
| 145 | JkOptions +ForwardURICompatUnparsed |
| 146 | ---- |
| 147 | |
Shawn O. Pearce | 9ad8ba5 | 2009-12-11 19:06:21 -0800 | [diff] [blame] | 148 | GERRIT |
| 149 | ------ |
| 150 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 151 | |
| 152 | SEARCHBOX |
| 153 | --------- |