I'm trying to run uWsgi using uid
/gid
parameters in my wsgi ini file, so that it drops privileged access after starting.
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 uid
and gid
(nginx user and group), I get an error that is indicative of having a problem with my virtual env loading,
Traceback (most recent call last):
File "wsgi.py", line 14, in <module>
from app import app as application
File "/var/www/wsgi/flask-appbuilder/peds_registry/app/__init__.py", line 1, in <module>
import logging
ImportError: No module named logging
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.
My Nginx config's server/location directives are as follows:
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;
}
}
My uwsgi startup is:
#!/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 &
;;
stop)
pkill uwsgi
;;
restart)
$0 stop
$0 start
;;
*)
echo "usage: $0 (start|stop|restart|help)"
esac
And my uWsgi startup ini is:
[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
As stated, this loads fine without the gid/uid parameters, but when I add
uid = nginx
gid = nginx
to the ini file, I get the error noted above.
All my searches yield permissions with the socket, but my problem seems to be loading modules from within the virtual environment.
On a side note: I am using uWsgi installed from pip into my virtual environment.