Issue running uWsgi using pid/gid
<p>I'm trying to run uWsgi using <code>uid</code>/<code>gid</code> parameters in my wsgi ini file, so that it drops privileged access after starting.</p>

<p>Note: Everything works fine as expected when I remove these two parameters from my ini file. Also, there are no issues with my socket. However, when I run with a specified <code>uid</code> and <code>gid</code> (nginx user and group), I get an error that is indicative of having a problem with my virtual env loading, </p>

<p><code>Traceback (most recent call last):
  File "wsgi.py", line 14, in &lt;module&gt;
    from app import app as application
  File "/var/www/wsgi/flask-appbuilder/peds_registry/app/__init__.py", line 1, in &lt;module&gt;
    import logging
ImportError: No module named logging</code></p>

<p>Again, this work fine when running without gid/pid. Also, note that the user and group nginx both exist and both have ownership on the python project's directory structure.</p>

<p>My Nginx config's server/location directives are as follows:</p>

<pre><code>server {
    listen 80;
    server_name  hostname.domain;
    return 301 https://$host$request_uri;
}
server {
    listen        443 ssl;
    server_name  hostname.domain;
    ssl_certificate /etc/ssl/certs/host.chained.crt;
    ssl_certificate_key /etc/ssl/certs/host.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

location /test {
            include uwsgi_params;
            uwsgi_pass unix:/tmp/uwsgi.sock;
    }
}
</code></pre>

<p>My uwsgi startup is:</p>

<pre><code>#!/bin/sh
# chkconfig: - 99 10
FLASK_HOME=/var/www/wsgi/flask-appbuilder
export PEDS_HOME
ACTIVATE_CMD=/var/www/wsgi/flask-appbuilder/venv/bin/activate
case "$1" in
start)
    cd $FLASK_HOME
    source $ACTIVATE_CMD
    uwsgi  -s /tmp/uwsgi.sock -H ./venv/ --ini /var/www/wsgi/flask-appbuilder/test.ini --virtualenv /var/www/wsgi/flask-appbuilder/venv --chmod-socket=666  --manage-script-name --mount /test=run:app --wsgi-file wsgi.py --logto test.log &amp;
    ;;
stop)
    pkill uwsgi
    ;;
restart)
    $0 stop
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"
esac
</code></pre>

<p>And my uWsgi startup ini is:</p>

<pre><code>[uwsgi]
socket = /tmp/uwsgi.sock
chdir = /var/www/wsgi/flask-appbuilder/peds_registry
wsgi-file = wsgi.py
pyhome = /var/www/wsgi/flask-appbuilder/venv
callable = app
manage-script-name = true
mount: /test=run.py 
</code></pre>

<p>As stated, this loads fine without the gid/uid parameters, but when I add</p>

<pre><code>uid = nginx
gid = nginx
</code></pre>

<p>to the ini file, I get the error noted above. </p>

<p>All my searches yield permissions with the socket, but my problem seems to be loading modules from within the virtual environment. </p>

<p>On a side note: I am using uWsgi installed from pip into my virtual environment.</p>