TeamCity、nginx 和 Websockets - 501 错误

TeamCity、nginx 和 Websockets - 501 错误

我目前正在 nginx 反向代理后面设置 TeamCity,但我的浏览器中出现错误。错误如下:

WebSocket connection to 'ws://ci.example.net/app/subscriptions?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.7-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true&browserLocationHost=http%3A%2F%2Fci.example.net' failed: Error during WebSocket handshake: Unexpected response code: 501

我查看了 nginx 错误日志和 TeamCity 错误日志,结果都是空的。

我的 nginx 配置如下:

server {
  listen 80;
  server_name ci.example.net;

  error_log /var/log/nginx/error.log;
  proxy_intercept_errors on;

  error_page 401 403 404 /404.html;

  location / {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_pass          http://127.0.0.1:8111;
    proxy_read_timeout  90;

    proxy_redirect      http://127.0.0.1:8111 http://ci.fluxmc.net;
  }
}

#Websocket configuration
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''   '';
}

server {
    listen 400;
    server_name ci.example.net;

    error_log /var/log/nginx/error.log;
    proxy_intercept_errors on;

    location /tc {
        proxy_pass http://localhost:8111/tc;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $server_name:$server_port;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

我真的不知道接下来该去哪里,我已经关注了TeamCity 文档几乎完全一样。如果您能提供任何帮助,我将不胜感激!

答案1

TeamCity 的文档使一些假设以下情况不适合您:

TeamCity 服务器安装在以下 URL:http://teamcity.local:8111/tc

外界可以通过以下 URL 看到它:http://teamcity.public:400/tc

在您的情况下,TeamCity 对外界可见的 URL 是:http://ci.example.net

这将更改你的 NGINX 配置,如下所示:

server {
  listen 80;
  server_name ci.example.net;

  error_log /var/log/nginx/error.log;
  proxy_intercept_errors on;

  error_page 401 403 404 /404.html;

  location / {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_pass          http://127.0.0.1:8111;
    proxy_read_timeout  90;

    proxy_redirect      http://127.0.0.1:8111 http://ci.fluxmc.net;
    proxy_http_version  1.1;
    proxy_set_header    Upgrade $http_upgrade;
    proxy_set_header    Connection $connection_upgrade;
  }
}

#Websocket configuration
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''   '';
}

对我来说,这足以使与 TeamCity 的 websocket 连接正常工作。

相关内容