# If your httpd frontend is https but you are proxying http Gitblit WAR or GO\r
#Header edit Location ^http://([^⁄]+)/gitblit/ https://$1/gitblit/\r
\r
+# Additionally you will want to tell Gitblit the original scheme and port\r
+#Header set X-Forwarded-Proto https\r
+#Header set X-Forwarded-Port 443\r
+\r
#ProxyPass /gitblit ajp://localhost:8009/gitblit\r
%ENDCODE% \r
**Please** make sure to: \r
\r
#### fixes\r
\r
+- Repository URL uses `X-Forwarded-Proto` and `X-Forwarded-Port`, if available, for reverse proxy configurations (issue 115)\r
- Fixes to relative path determination in repository searh algorithm for symlinks (issue 116)\r
- Output real RAW content, not simulated RAW content (issue 114)\r
- Fixed Lucene charset encoding bug when reindexing a repository (issue 112)\r
* @return the host url\r
*/\r
public static String getGitblitURL(HttpServletRequest request) {\r
+ // default to the request scheme and port\r
+ String scheme = request.getScheme();\r
+ int port = request.getServerPort();\r
+\r
+ // try to use reverse-proxy server's port\r
+ String forwardedPort = request.getHeader("X-Forwarded-Port");\r
+ if (StringUtils.isEmpty(forwardedPort)) {\r
+ forwardedPort = request.getHeader("X_Forwarded_Port");\r
+ }\r
+ if (!StringUtils.isEmpty(forwardedPort)) {\r
+ // reverse-proxy server has supplied the original port\r
+ try {\r
+ port = Integer.parseInt(forwardedPort);\r
+ } catch (Throwable t) {\r
+ }\r
+ }\r
+ \r
+ // try to use reverse-proxy server's scheme\r
+ String forwardedScheme = request.getHeader("X-Forwarded-Proto");\r
+ if (StringUtils.isEmpty(forwardedScheme)) {\r
+ forwardedScheme = request.getHeader("X_Forwarded_Proto");\r
+ }\r
+ if (!StringUtils.isEmpty(forwardedScheme)) {\r
+ // reverse-proxy server has supplied the original scheme\r
+ scheme = forwardedScheme;\r
+ \r
+ if ("https".equals(scheme) && port == 80) {\r
+ // proxy server is https, inside server is 80\r
+ // this is likely because the proxy server has not supplied\r
+ // x-forwarded-port. since 80 is almost definitely wrong,\r
+ // make an educated guess that 443 is correct.\r
+ port = 443;\r
+ }\r
+ }\r
+ \r
StringBuilder sb = new StringBuilder();\r
- sb.append(request.getScheme());\r
+ sb.append(scheme);\r
sb.append("://");\r
sb.append(request.getServerName());\r
- if ((request.getScheme().equals("http") && request.getServerPort() != 80)\r
- || (request.getScheme().equals("https") && request.getServerPort() != 443)) {\r
- sb.append(":" + request.getServerPort());\r
+ if (("http".equals(scheme) && port != 80)\r
+ || ("https".equals(scheme) && port != 443)) {\r
+ sb.append(":" + port);\r
}\r
sb.append(request.getContextPath());\r
return sb.toString();\r