nginx无法连接到kestrel

时间:2015-12-07 14:55:16

标签: ubuntu nginx dnx kestrel-http-server

我在Ubuntu服务器上使用DNX 4.5.1和RC1 update 1运行时。我的后端应用程序在Kestrel上运行,监听localhost:5004。我的前端是nginx,它将请求重定向到后端。但由于某些原因,nginx无法连接到Kestrel:

2015/12/07 15:31:44 [error] 2263#0: *7 upstream timed out (110: Connection timed out) while reading upstream, client: 192.168.33.1, server: ribandelle.lan, request: "GET /api/track/2 HTTP/1.1", upstream: "http://127.0.0.1:5004/api/track/2", host: "ribandelle.lan"

我的应用程序启动并运行:

arnaud@ubuntu:/var/log/nginx$ sudo netstat -tap | grep mono tcp 0 0 localhost:5004 *:* LISTEN 2389/mono
tcp 0 0 localhost:48663 localhost:mysql ESTABLISHED 2389/mono

(第二行是我的应用程序连接到数据库)。

我在project.json文件中尝试过各种服务器选项。我试图让Kestrel听取http://*:5004http://localhost:5004http://127.0.0.1:5004。似乎没有工作。在我的nginx配置中,我也尝试过后端(localhost和127.0.0.1)的不同地址也没有成功。这是我的nginx配置:

upstream backend  {
        server 127.0.0.1:5004;
}
limit_req_zone $binary_remote_addr zone=api:10m rate=5r/s;
server {
        listen      80;
        server_name ribandelle.lan;

        location / {
            limit_req zone=api burst=15;
            proxy_pass http://backend;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
        }
    }

nginx是Ubuntu 15.04上的1.6.2版本。我不确定什么是错的,任何帮助都会受到赞赏!

1 个答案:

答案 0 :(得分:2)

显然我在发布问题之前看起来并不够努力,因为它已经在那里被问到:ASP.NET 5 behind nginx

似乎Kestrel中存在一个错误,您需要在nginx配置中启用Keep-Alive标头才能使其正常工作。