我在我的网络服务器上使用捆绑Nginx + Gunicorn + Pserve(金字塔)来运行多个站点。确切地说,现在只有两个站点在工作。如果我把它正确 Nginx 侦听 80 端口并在5000和5010端口上代理对Gunicorn的请求,这是我的nginx配置两个域:
# $ cat cat /etc/nginx/sites-available/domain1.ru
upstream domain1.ru {
server 0.0.0.0:5000;
server 0.0.0.0:5001;
}
server {
listen 80;
server_name www.domain1.ru domain1.ru;
error_log /var/log/nginx/domain1.ru.error.log;
access_log /var/log/nginx/domain1.ru.access.log;
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header Host $http_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;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 60s;
proxy_send_timeout 90s;
proxy_read_timeout 90s;
proxy_buffering off;
proxy_temp_file_write_size 64k;
proxy_pass http://127.0.0.1:5000;
proxy_redirect off;
}
}
# $ cat cat /etc/nginx/sites-available/domain2.ru
upstream domain2.ru {
server 0.0.0.0:5010;
server 0.0.0.0:5011;
}
server {
listen 80;
server_name www.domain2.ru domain2.ru;
error_log /var/log/nginx/domain2.ru.error.log;
access_log /var/log/nginx/domain2.ru.access.log;
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header Host $http_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;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 60s;
proxy_send_timeout 90s;
proxy_read_timeout 90s;
proxy_buffering off;
proxy_temp_file_write_size 64k;
proxy_pass http://127.0.0.1:5010;
proxy_redirect off;
}
}
这两个网站运行良好,但当我添加相同的配置,除了将端口更改为5015和5016出错了。当我刚刚开始 pserve 进程时,我收到了一个错误:
$ pserve production.ini --reload --log-file=domain3.ru-pserve.log
Starting subprocess with file monitor
Traceback (most recent call last):
File "/var/www/eba/data/gs/env/bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.4.5', 'console_scripts', 'pserve')()
File "/var/www/eba/data/gs/env/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/var/www/eba/data/gs/env/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
return ep.load()
File "/var/www/eba/data/gs/env/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/var/www/eba/data/gs/env/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 28, in <module>
from pyramid.compat import WIN
File "/var/www/eba/data/gs/env/lib/python2.7/site-packages/pyramid/compat.py", line 114, in <module>
from urllib2 import urlopen as url_open
File "/var/www/eba/data/gs/env/opt/Python-2.7.3/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/var/www/eba/data/gs/env/opt/Python-2.7.3/lib/python2.7/httplib.py", line 69, in <module>
from array import array
ImportError: /var/www/eba/data/gs/env/lib/python2.7/lib-dynload/array.so: cannot open shared object file: Too many open files in system
当我再次运行pserve时,我又遇到了另一个错误,这里只是最后几行:
File "/var/www/eba/data/gs/env/opt/Python-2.7.3/lib/python2.7/random.py", line 70, in <module>
import _random
ImportError: /var/www/eba/data/gs/env/lib/python2.7/lib-dynload/_random.so: cannot open shared object file: Too many open files in system
下一次 - 另一次:
File "/var/www/eba/data/gs/env/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 3, in <module>
from __future__ import with_statement
ImportError: No module named __future__
事情是,如果我关闭了第二个网站并在第3次再次运行pserve - 它运行正常。
我不知道它必须有什么限制。也许是因为我在〜/ gs / env 文件夹中使用一个环境运行所有应用程序。端口 5015 和 5016 是免费的。
答案 0 :(得分:2)
这听起来像是在一个非常大的文件夹中使用--reload
的问题。尝试删除该参数,因为您无论如何都不应该在生产环境中使用它。
答案 1 :(得分:0)
这是服务器问题。我只是耗尽了所有可用的记忆。对于三个php网站(mod-fpm)和三个金字塔网站以及mongo来说,512Mb是不够的。第一个错误是关键 - 系统中打开的文件过多。
ulimit -a 向我展示了1024个可用文件,但增加该值没有结果。因此,我将关税计划改为1024Mb,现在已经足够了 - 所有工作都很好而且速度很快。