user1356863
user1356863

Reputation: 143

Run uwsgi emperor mode gives nginx errors

If I run uwsgi normally (non-emperor mode) nginx works perfectly.

If I configure uwsgi in emperor mode I get various errors that I am unable to resolve.

Here is my nginx.conf file:

worker_processes  1;
worker_rlimit_nofile 8192;

events {
    worker_connections  8192;
    #multi_accept on;      # does not matter if I use multi-accept
    use epoll;             #   or epoll, same errors
}

http {
    large_client_header_buffers  2  1k;       
    client_body_buffer_size     10k;           
    client_header_buffer_size    1k;           
    client_max_body_size         8m;           
    request_pool_size           32k;
    connection_pool_size        256;
    ignore_invalid_headers       on;

        sendfile        on;
    tcp_nopush      on;
    server_names_hash_bucket_size 128;
    keepalive_timeout  90;
    gzip               on;
    gzip_http_version 1.0;
    gzip_proxied      any;
    gzip_min_length   500;
    gzip_disable      "MSIE [1-6]\.";
    gzip_types        text/plain text/xml text/css
                      text/comma-separated-values
                      text/javascript
                      application/x-javascript
                      application/atom+xml;

    # Configuration for Nginx
    server  {
        # Running port
        listen 80;
        listen 127.0.0.1:27070;              
        server_name 127.0.0.1 myserver_name.com;
        charset utf-8;
        access_log  /log/nginx_access.log;
        error_log  /log/nginx_error.log;   

        # Proxying connections to application servers
        location /myapplication/ {
             include             uwsgi_params;
             uwsgi_buffering     off;
             uwsgi_param         SCRIPT_NAME /myapplication;
             uwsgi_modifier1     30;
             uwsgi_pass          127.0.0.1:27070;  
             proxy_pass          http://127.0.0.1:27070;
             proxy_redirect      off;
             proxy_set_header    Host $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-host $server_name;
        }   # end mysite
   }   # end server
}   # end http

vassals-default.ini file:

[uwsgi]
log-date = true
emperor=/etc/uwsgi
emperor-use-clone = fs,net,ipc,pid,uts
emperor-tyrant = true
vassals-include = /opt/uwsgi/vassals-default.ini
master = true
cap = setgid, setuid
vassal-set = processes=8
vassal-set = enable-metrics=1
vassal_name = %n
socket = /tmp/sockets/%n.sock
chmod-socket = 770
logto = /opt/uwsgi/%n.log

myapplication.ini file:

[uwsgi]
domain = myserver_name.com
app-name = myapplication
uid = myapplication
gid = myapplication
socket=/tmp/sockets/myapplication.sock
chdir = /opt/myapplication/myapp
virtualenv = /opt/myapplication/webapp-20150203/
module = WSGI:app
callable = app
processes = 2
buffer-size=32768
http-buffer-size=32768
daemonize = /opt/uwsgi/myapplication.log
pidfile = /opt/uwsgi/myapplication.pid
logto = /opt/uwsgi/uwsgi.log
debug = true
disable-logging = false
thunder-lock = true
enable-threads = true
harakiri = 30 

Sockets file:

[root@npi uwsgi]# ls -l /tmp/sockets
srwsrws--- 1 sadlesum sadlesum 0 Jul 16 13:48 myapplication.sock
srwxrwx--- 1 root     root     0 Jul 16 13:48 vassals-default.sock

Log files look good:

myapplication.log:

Thu Jul 16 13:48:25 2015 - *** starting uWSGI sub-Emperor ***
Thu Jul 16 13:48:25 2015 - announcing my loyalty to the Emperor...
Thu Jul 16 13:48:25 2015 - uwsgi socket 0 bound to UNIX address /tmp/sockets/myapplication.sock fd 3
Thu Jul 16 13:48:25 2015 - uwsgi socket 1 bound to UNIX address /tmp/sockets/vassals-default.sock fd 4
Thu Jul 16 13:48:25 2015 - Python version: 2.7.6 (default, Jan 11 2014, 21:49:01)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
Thu Jul 16 13:48:25 2015 - Set PythonHome to /opt/myapplication/webapp-20150203/
Thu Jul 16 13:48:25 2015 - Python main interpreter initialized at 0x10f7470
Thu Jul 16 13:48:25 2015 - python threads support enabled
Thu Jul 16 13:48:25 2015 - your server socket listen backlog is limited to 100 connections
Thu Jul 16 13:48:25 2015 - your mercy for graceful operations on workers is 60 seconds
Thu Jul 16 13:48:25 2015 - mapped 304320 bytes (297 KB) for 2 cores
Thu Jul 16 13:48:25 2015 - *** Operational MODE: preforking ***
Thu Jul 16 13:48:29 2015 - WSGI app 0 (mountpoint='') ready in 4 seconds on interpreter 0x10f7470 pid: 26688 (default app)
Thu Jul 16 13:48:29 2015 - *** uWSGI is running in multiple interpreter mode ***
Thu Jul 16 13:48:29 2015 - spawned uWSGI master process (pid: 26688)
Thu Jul 16 13:48:29 2015 - spawned uWSGI worker 1 (pid: 26703, cores: 1)
Thu Jul 16 13:48:29 2015 - spawned uWSGI worker 2 (pid: 26704, cores: 1)

Starting uwsgi in emperor mode:

uwsgi --emperor /opt/uwsgi --vassals-include /opt/uwsgi/vassals-default.ini --master --die-on-term

*** starting uWSGI Emperor ***
Python version: 2.7.6 (default, Jan 11 2014, 21:49:01)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from saddlesum.ini
[uWSGI] getting INI configuration from /opt/uwsgi/vassals-default.ini
*** has_emperor mode detected (fd: 7) ***
[uWSGI] getting INI configuration from vassals-default.ini
[uWSGI] getting INI configuration from /opt/uwsgi/vassals-default.ini
Thu Jul 16 13:48:25 2015 - [emperor] vassal myapplication.ini is now loyal
Thu Jul 16 13:48:25 2015 - [emperor] vassal vassals-default.ini is now loyal
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xb16870
your mercy for graceful operations on workers is 60 seconds
*** Operational MODE: no-workers ***
spawned uWSGI master process (pid: 26686)
Thu Jul 16 13:48:25 2015 - [emperor] vassal vassals-default.ini has been spawned
Thu Jul 16 13:48:25 2015 - [emperor] vassal vassals-default.ini is ready to accept requests
Thu Jul 16 13:48:29 2015 - [emperor] vassal myapplication.ini has been spawned
Thu Jul 16 13:48:29 2015 - [emperor] vassal myapplication.ini is ready to accept requests

When I try to access my webapp in firefox (or Chrome) I get the following errors:

If I have this line in my nginx.conf file:

proxy_pass          http://127.0.0.1:27070;

Error 400 bad request when proxy_pass line above is present in nginx.conf file:

Error 400 bad request

Error 502 bad gateway when proxy_pass line above is commented out in nginx.conf file:

502 bad gateway result

Additionally, when getting the 502 bad gateway error, I also see this in my nginx_error.log file:

2015/07/16 14:10:18 [error] 28289#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /myapplication/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:27070", host: "myserver_name.com", referrer: "http://myserver_name.com/"

Upvotes: 2

Views: 3485

Answers (1)

oilymemoryleak
oilymemoryleak

Reputation: 1

try to add localhost or you ip/domain to ALLOWED_HOSTS in setting.py like this

ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'your.server.ip.here']

also remove these :

listen 127.0.0.1:27070;

uwsgi_pass 127.0.0.1:27070;

proxy_pass http://127.0.0.1:27070;

and make nginx use unix socket instead as in your ini file

socket=/tmp/sockets/myapplication.sock

Upvotes: 0

Related Questions