Can't run over two sites using Nginx + Pyramid + Gunicorn

Can't run over two sites using Nginx + Pyramid + Gunicorn

Postby Mudak » Mon May 26, 2014 6:51 am

Hi!

I use bundle Nginx + Gunicorn + Pserve (Pyramid) on my web server to run several sites. To be exact only two sites now working. If I put it right Nginx listens 80 port and proxying requests to Gunicorn on 5000 and 5010 ports, here is my nginx configs for two domains:

Code: Select all
# $ 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;
    }
}


And these two sites works well, but when I added just the same config except changing ports to 5015 and 5016 something went wrong. When I just started pserve process I got an error:

Code: Select all
$ 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


When I run pserve again I got another error, here is just last several lines:
Code: Select all
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


Next time - another:
Code: Select all
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__


Strange thing is - if I switched off the second site and run pserve again on 3rd - it runs okay. The ports 5015 and 5016 are free. All applications use one environment located in /var/www/eba/data/gs/env/
Last edited by stranac on Mon May 26, 2014 7:32 am, edited 1 time in total.
Reason: First post lock.
Mudak
 
Posts: 1
Joined: Mon May 26, 2014 6:46 am

Return to Web Development

Who is online

Users browsing this forum: No registered users and 2 guests