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;
    }
}

我真的不确定从哪里开始,我几乎完全遵循了documentation for TeamCity.如果您能提供任何帮助,我将不胜感激!

最佳答案
TeamCity的文档使a couple of assumptions无法满足您的要求:

TeamCity server is installed at URL: 07001

It is visible to the outside world as URL: 07002

在您的情况下,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连接工作.

原文链接:https://www.f2er.com/nginx/435477.html

猜你在找的Nginx相关文章