Cannot access TeamCity behind Nginx

Answered

I use Ubuntu 20.04 and I have downloaded TeamCity and changed the connector inside /conf/server.xml to:

 <Connector port="8111" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="60000"
redirectPort="8543"
useBodyEncodingForURI="true"
socket.txBufSize="64000"
socket.rxBufSize="64000"
tcpNoDelay="1"
proxyName="internal.mydomain.com"
proxyPort="443"
secure="true"
scheme="https"
/>

I adapted the nginx.conf to:

server {
    server_name internal.mydomain.com;
    location /teamcity/ {
        proxy_read_timeout 1200;
        proxy_connect_timeout 240;
        client_max_body_size 0; # maximum size of an HTTP request. 0 allows uploading large artifacts to TeamCity

        proxy_pass http://localhost:8111/; # full internal address
        proxy_http_version 1.1;
        proxy_set_header Host $server_name:$server_port;
        proxy_set_header X-Forwarded-Host $http_host; # necessary for proper absolute redirects and TeamCity CSRF check
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Upgrade $http_upgrade; # WebSocket support
        proxy_set_header Connection $connection_upgrade; # WebSocket support
}

listen 443 ssl; # managed by Certbot
ssl_certificate ...; # managed by Certbot
ssl_certificate_key ... # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

I start TeamCity with ./teamcity-server.sh run and open my webbrowser and enter https://internal.mydomain.com/teamcity/ I get the following page:

TeamCity Maintenance

Confirming TeamCity first start

TeamCity server requires technical maintenance. Please let the server administrator know this.

TeamCity 2020.1 (build 78475)
 
When I look into /var/log/nginx/error.log, I see:
"/usr/share/nginx/html/css/react-ui.css" failed (2: No such file or directory), client: 91.114.173.225, server: internal.mydomain.com, request: "GET /css/react-ui.css HTTP/1.1", host: "internal.mydomain.com", referrer: "https://internal.mydomain.com/teamcity/"
2020/06/16 11:57:20 [error] 195749#195749: *82 open() "/usr/share/nginx/html/js/ring/loaderInline.css" failed (2: No such file or directory), client: 91.114.173.225, server: internal.mydomain.com, request: "GET /js/ring/loaderInline.css HTTP/1.1", host: "internal.mydomain.com", referrer: "https://internal.mydomain.com/teamcity/"
2020/06/16 11:57:20 [error] 195749#195749: *84 open() "/usr/share/nginx/html/js/ring/loaderInline.js" failed (2: No such file or directory), client: 91.114.173.225, server: internal.mydomain.com, request: "GET /js/ring/loaderInline.js HTTP/1.1", host: "internal.mydomain.com", referrer: "https://internal.mydomain.com/teamcity/"
2020/06/16 11:57:20 [error] 195749#195749: *83 open() "/usr/share/nginx/html/js/jquery/jquery-1.12.1.min.js" failed (2: No such file or directory), client: 91.114.173.225, server: internal.mydomain.com, request: "GET /js/jquery/jquery-1.12.1.min.js HTTP/1.1", host: "internal.mydomain.com", referrer: "https://internal.mydomain.com/teamcity/"
2020/06/16 11:57:20 [error] 195749#195749: *78 open() "/usr/share/nginx/html/maintenance/maintenance.js" failed (2: No such file or directory), client: 91.114.173.225, server: internal.mydomain.com, request: "GET /maintenance/maintenance.js HTTP/1.1", host: "internal.mydomain.com", referrer: "https://internal.mydomain.com/teamcity/"
2020/06/16 11:57:20 [error] 195749#195749: *78 open() "/usr/share/nginx/html/js/clipboard.min.js" failed (2: No such file or directory), client: 91.114.173.225, server: internal.mydomain.com, request: "GET /js/clipboard.min.js HTTP/1.1", host: "internal.mydomain.com", referrer: "https://internal.mydomain.com/teamcity/"
2020/06/16 11:57:20 [error] 195749#195749: *78 open() "/usr/share/nginx/html/js/bs/bs-clipboard.js" failed (2: No such file or directory), client: 91.114.173.225,

What am I doing wrong?

1 comment
Comment actions Permalink

Ok i got it. Was quite tricky.

1. First and dumbest mistake: I didn't wait until the server has completely booted. It takes quite some time but finally it shows:


TeamCity initialized, server UUID: 34aad1d7-68b2-4f21-8ff5-dc27e6e250c4, URL: localhost:8111
TeamCity is running in professional mode
[TeamCity] Super user authentication token: 4540906993426727523 (use empty username with the token as the password to access the server)

2. I changed my nginx.conf to:

server {
server_name internal.mydomain.com;
location /teamcity/ {
proxy_read_timeout 1200;
proxy_connect_timeout 240;
client_max_body_size 0; # maximum size of an HTTP request. 0 allows uploading large artifacts to TeamCity

proxy_pass http://localhost:8111/teamcity; # full internal address
proxy_http_version 1.1;
proxy_set_header Host $server_name:$server_port;
proxy_set_header X-Forwarded-Host $http_host; # necessary for proper absolute redirects and TeamCity CSRF check
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Upgrade $http_upgrade; # WebSocket support
proxy_set_header Connection $connection_upgrade; # WebSocket support
}

listen 443 ssl; # managed by Certbot
ssl_certificate ...; # managed by Certbot
ssl_certificate_key ... # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

3. I changed my /conf/server.xml to:

 <Connector port="8111" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="60000"
redirectPort="8543"
useBodyEncodingForURI="true"
socket.txBufSize="64000"
socket.rxBufSize="64000"
tcpNoDelay="1"
proxyName="internal.mydomain.com/teamcity"
proxyPort="443"
secure="true"
scheme="https"
/>

 

4. I changed webapps/ROOT to webapps/teamcity as described here: https://www.jetbrains.com/help/teamcity/installing-and-configuring-the-teamcity-server.html#InstallingandConfiguringtheTeamCityServer-ChangingServerContext

5. I changed rootURL=localhost:8111 in ~/.BuildServer/config/main-config.xml

 

Finally it is reachable under https://internal.mydomain.com/teamcity

0

Please sign in to leave a comment.