【发布时间】:2015-12-07 14:55:15
【问题描述】:
我在 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://*:5004、http://localhost:5004 和 http://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 版本。我不确定出了什么问题,我们将不胜感激!
【问题讨论】:
-
我应该补充一点,如果我监听服务器的实际 IP(即:
http://192.168.33.128:5004)从而绕过 nginx,那么我可以正常访问应用程序。
标签: ubuntu nginx dnx kestrel-http-server