Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity behind nginx proxy

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/;
}
like image 985
Marcelo Cantos Avatar asked May 20 '11 11:05

Marcelo Cantos


2 Answers

I did this using the standard Teamcity Windows installer, and presumably it would work on any platform.

Change Teamcity Location

As per a comment by a JetBrains employee:

To change TeamCity address from http://server/ to http://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.

Proxy configuration

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>

Redirect old URL

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).

like image 176
gregmac Avatar answered Sep 28 '22 06:09

gregmac


(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.

like image 30
Marcelo Cantos Avatar answered Sep 28 '22 08:09

Marcelo Cantos