我已经实现了一个播放!应用程序在我的服务器中有两个不同的实例(比如说 %inst1 和 %inst2),以避免在预编译任何更新时出现停机时间。我已经配置 nginx 来获得负载均衡器。对于每个实例,我都有自己的子目录,并且我已正确配置文件 application.conf 以获取 %inst1 和 %inst2 的不同端口。nginx的配置文件是这样的:
upstream myapp {
server localhost:9031;
server localhost:9032;
}
server {
server_name www.example.com;
access_log /var/log/nginx/myapp.access.log;
location / {
proxy_pass http://myapp;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
当我在开发模式下尝试此配置时,它可以完美运行。我执行这两个实例,每当我停止其中一个以更新它时,所有流量都会流向另一个实例,而不会造成任何停机。当我再次重新启动应用程序并重新加载 nginx 时,两个实例都运行良好。
当我将实例配置为生产模式时出现问题。我只更改 application.conf 从:
%inst1.application.mode=dev
%inst2.application.mode=dev
至:
%inst1.application.mode=prod
%inst2.application.mode=prod
然后我无法让两个实例同时工作两次。每当我启动第二个时,我都会收到 502 Bad Gateway 错误。然后我检查第一个实例的状态,我收到以下错误:
$ play status --%inst1
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.2.4, http://www.playframework.org
~ framework ID is inst1
~
~ Cannot contact the application...
~
另外,我不能以这样的错误开始它:
Oops. /usr/share/apps/klingstore1 is already started! (or delete /usr/share/apps/klingstore1/server.pid)
也不停止:
Play was not running (Process id 11657 not found)
而且我必须手动删除 server.pid 。然后我再次启动它并在另一个实例中再次发生。
你有什么线索吗?
谢谢!!
解决了:
最后,这似乎只是RAM的问题。实例在相同的 Play 配置下正常工作!和 Nginx 在各种日子里都没有问题。