I am trying to set up TeamCity behind nginx. I'd like https://public.address.com/teamcity/... to redirect to http://127.0.0.1:8111/..., but even though nginx does this successfully, the login page comes back with references that look like this:
<script type="text/javascript" src="/res/-8762791360234593415.js?v=1305815890782"></script>
Obviously, this won't do, and fiddling with the rootURL
setting (Server URL: in Server Configuration) doesn't make any difference.
How do I run TeamCity behind a proxy under a non-root URL?
FWIW, here's the relevant portion of my nginx config:
location /teamcity/ {
proxy_pass http://127.0.0.1:8111/;
proxy_redirect http://127.0.0.1:8111/ https://$host/teamcity/;
}
I did this using the standard Teamcity Windows installer, and presumably it would work on any platform.
As per a comment by a JetBrains employee:
To change TeamCity address from
http://server/
tohttp://server/teamcity/
, rename the<TeamCity home>\webapps\ROOT
directory to<TeamCity home>\webapps\teamcity
.
Note also that you'll need to rename this directory every time you upgrade Teamcity.
The nginx config then looks something like:
location /teamcity/ {
proxy_pass http://teamcity-server.domain.com/teamcity/;
}
Or you can use Apache (I switched to Apache due to authentication requirements I had):
<Location /teamcity>
ProxyPass http://teamcity-server.domain.com/teamcity
ProxyPassReverse http://teamcity-server.domain.com/teamcity
</Location>
I also created a new <Teamcity home>\webapps\ROOT
, and put a index.jsp
file into it, which redirects to the new URL so old links continue to work (eg, if someone goes to http://teamcity-server.domain.com it redirects to http://teamcity-server.domain.com/teamcity):
<!DOCTYPE html>
<html>
<head>
<title>TeamCity</title>
<meta http-equiv="refresh" content="0;url=/teamcity/overview.html"/>
</head>
<body>
<!-- no content -->
</body>
</html>
You could also do the redirect in nginx/apache, but doing on the Teamcity server means if someone goes to the old URL directly on the teamcity web server (instead of via your proxy) they'll still get correctly redirected (instead of a 404).
(I eventually tracked down a solution myself...)
Install tomcat, then install the WAR version of TeamCity, which is in the download area above the Java EE Container tab. This exposes TeamCity under a base URL that you can choose at the time you install the WAR.
The simplest approach is to copy the .war file into Tomcat's webapps directory, giving it a name that matches the desired base URL. For instance, installing teamcity.war
into $TOMCAT_HOME/webapps
will load TeamCity under the url http://localhost:8080/teamcity
(assuming the default Tomcat install). Proxying from https://public.address.com/teamcity
to this internal address should be fairly straighforward in nginx.
I had trouble getting it to run immediately after I installed the .war file, but after restarting Tomcat, it all came good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With