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