在 Ubuntu MVC4 应用程序上使用 nginx、PostgreSQL 和 Mono“在从上游读取响应标头时上游过早关闭连接”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29359484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"upstream prematurely closed connection while reading response header from upstream" with nginx, PostgreSQL and Mono on Ubuntu MVC4 app
提问by Erwin Rooijakkers
/Edit I done the suggestion of the answer to the question mentioned aboveto give access rights to the registry as follows:
/编辑我完成了对上述问题的回答的建议,以提供对注册表的访问权限,如下所示:
sudo mkdir -p /usr/local/etc/mono/registry
sudo chmod uog+rw /usr/local/etc/mono/registry
This did not help, as the bad gateway problem only appears afterhaving given access to the registry with the above commands (before that I got the registry error).
这没有帮助,因为错误网关问题仅在使用上述命令访问注册表后才会出现(在此之前我收到注册表错误)。
Question: I want to deploy a MVC 4 app running on Mono runtime with nginx to an Ubuntu server of Azure. By selecting such a Ubuntu server and running an installer script I managed to have a default web application running and visible on oogstplanner.cloudapp.net. The installer worked as follows:
问题:我想将运行在 Mono 运行时和 nginx 的 MVC 4 应用程序部署到 Azure 的 Ubuntu 服务器。通过选择这样的 Ubuntu 服务器并运行安装程序脚本,我设法在 oogstplanner.cloudapp.net 上运行并显示了一个默认的 Web 应用程序。安装程序的工作方式如下:
wget https://bitbucket.org/mindbar/install-mono/raw/master/install-nginx-
mono.sh && sudo chmod +x install-nginx-mono.sh && ./install-nginx-mono.sh
The script installed nginx and mono and setup the nginx.conf and other configuration files.
该脚本安装了 nginx 和 mono 并设置了 nginx.conf 和其他配置文件。
What I then did was remove this installation, installed postgresql and setup the database, and replaced the files in $HOME/www/ with my own MVC 4 web application which works locally by copying it there. Then when running it I see a
然后我做的是删除这个安装,安装 postgresql 并设置数据库,并用我自己的 MVC 4 Web 应用程序替换 $HOME/www/ 中的文件,该应用程序通过将其复制到本地工作。然后在运行它时我看到一个
error.
错误。
The log file /var/log/nginx/error.log says (for the first and subsequent requests):
日志文件 /var/log/nginx/error.log 说(对于第一个和后续请求):
2015/04/03 14:24:36 [error] 1305#0: *6 upstream prematurely closed connection while reading response header from upstream, client: my.ip.207, server: localhost, request: "GET /Account/Login?ReturnUrl=%2f HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "oogstplanner.cloudapp.net"
2015/04/03 14:26:05 [error] 1305#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: my.ip.207, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "oogstplanner.cloudapp.net"
2015/04/03 14:29:24 [error] 1305#0: *10 connect() failed (111: Connection refused) while connecting to upstream, client: my.ip.58, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "oogstplanner.cloudapp.net"
(...)
2015/04/03 14:24:36 [error] 1305#0: *6 从上游读取响应头时上游提前关闭连接,客户端:my.ip.207,服务器:本地主机,请求:“GET /Account/Login ?ReturnUrl=%2f HTTP/1.1”,上游:“fastcgi://127.0.0.1:9001”,主机:“oogstplanner.cloudapp.net”
2015/04/03 14:26:05 [错误] 1305#0: *8 connect() 连接到上游时失败(111:连接被拒绝),客户端:my.ip.207,服务器:localhost,请求:“GET / HTTP/1.1”,上游:“fastcgi://127.0.0.1: 9001", 主机: "oogstplanner.cloudapp.net"
2015/04/03 14:29:24 [error] 1305#0: *10 connect() failed (111: Connection denied) 连接上游时,客户端:my. ip.58,服务器:本地主机,请求:“GET / HTTP/1.1”,上游:“fastcgi://127.0.0.1:9001", 主机: "oogstplanner.cloudapp.net"
(...)
So it does see that it needs to go to /Account/Login?ReturnUrl! Something isworking.
所以它确实看到它需要去 /Account/Login?ReturnUrl!有东西在起作用。
When I copy back a default app it works again.
当我复制回默认应用程序时,它会再次运行。
Configuration:
配置:
- Here is my /etc/nginx/nginx.conf.
- Here is my /etc/nginx/sites-available/mono-default(same for sites-enabled/monodefault)
- 这是我的 /etc/nginx/nginx.conf。
- 这是我的 /etc/nginx/sites-available/mono-default(与启用站点的/monodefault 相同)
/edit I have a strong suspicion that it has to do with the PostgreSQL database. This is because I just rebooted the server, and saw this NullReferenceException being thrown by NauckIt.PostgreSQLProvider:
/edit 我强烈怀疑它与 PostgreSQL 数据库有关。这是因为我刚刚重新启动了服务器,并看到 NauckIt.PostgreSQLProvider 抛出了这个 NullReferenceException:
This error always happens locally once, and then after a refresh the app works. But on the server the app does not work, but after not having the PostgreSQL provider throw a NullReferenceException I get the 502 error. So that is why I think the bad gateway might come from the PostgreSQL connection.
此错误总是在本地发生一次,然后在刷新后应用程序工作。但是在服务器上,该应用程序不起作用,但是在没有 PostgreSQL 提供程序抛出 NullReferenceException 之后,我收到了 502 错误。所以这就是为什么我认为坏网关可能来自 PostgreSQL 连接。
/Edit2 The plot thickens: when I look into the database I see (some) sessions being created in the Sessions table. I don't see any logic when that happens and have been unable to create a new one. But there has been a connection from the web app to the database sometimes.
/Edit2 情节变厚:当我查看数据库时,我看到在 Sessions 表中创建了(一些)会话。发生这种情况时我看不到任何逻辑,并且无法创建一个新逻辑。但是有时会从 Web 应用程序连接到数据库。
Here is the PostgreSQL log after a restart (at 14:25:23) and navigating to the website via a browser (at 14:24:36):
这是重启(14:25:23)并通过浏览器导航到网站(14:24:36)后的 PostgreSQL 日志:
2015-04-03 14:24:23 UTC LOG: database system is ready to accept connections
2015-04-03 14:24:23 UTC LOG: autovacuum launcher started
2015-04-03 14:24:23 UTC LOG: incomplete startup packet
2015-04-03 14:24:36 UTC LOG: could not receive data from client: Connection reset by peer
2015-04-03 14:24:23 UTC LOG:数据库系统已准备好接受连接
2015-04-03 14:24:23 UTC LOG:autovacuum 启动器启动
2015-04-03 14:24:23 UTC LOG:不完整启动数据包
2015-04-03 14:24:36 UTC 日志:无法从客户端接收数据:对等方重置连接
According to a reddit user:
根据一位 reddit 用户的说法:
502 Bad Gateway is an HTTP status code and cannot be returned by postgres because postgres doesn't speak HTTP. Similarly, NullReferenceException is a Mono exception and isn't thrown by postgres, so that's not a postgres problem either. Your application is attempting to send some data to postgres but crashes before it can finish doing so. This is an application problem, not a postgres problem. Hope this helps.
502 Bad Gateway 是一个 HTTP 状态代码,postgres 不能返回,因为 postgres 不说 HTTP。类似地,NullReferenceException 是一个 Mono 异常并且不会被 postgres 抛出,所以这也不是 postgres 的问题。您的应用程序正在尝试向 postgres 发送一些数据,但在完成之前崩溃了。这是一个应用程序问题,而不是 postgres 问题。希望这可以帮助。
Does anyone know what is wrong here?
有谁知道这里有什么问题?
PS I have all steps I've taken documented under the Deployment part in a READMEfile.
PS 我在自述文件的部署部分下记录了我采取的所有步骤。
回答by Murat Y?ld?z
The problem might be caused from originally disabling the http port and allowing only https. If have not been enabled, try to enable http port, only allow requests through 127.0.0.1. In addition to this also check the "timeout" values in the configuration settings. Hope this helps...
该问题可能是由于最初禁用 http 端口并仅允许 https 引起的。如果没有开启,尝试开启http端口,只允许通过127.0.0.1的请求。除此之外,还要检查配置设置中的“超时”值。希望这可以帮助...