I successfully managed to install:
NGINX + uWSGI + Flask
on a CentOS 6.x server
but I still have some doubts in terms of configuration:
1) I am running NGINX as a service: service nginx start/stop/restart
if I type "ps aux | grep nginx", I can see 2 processes:
- (by user root) master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
- (by user nginx) worker process
is that OK?
2) I setup a virtualenv for Flask and installed the uWSGI package under such virtualenv.
Currenty I am starting the uWSGI manually by typing "uwsgi /somedir/uwsgi.ini", where uwsgi.ini is as follows:
chdir = /myappdir
uid = pyuser
chmod-socket = 666
socket = /tmp/uwsgi.sock
module = run
callable = app
virtualenv = /myappdir/myvirtualenv
*** Python threads support is disabled. You can enable it with --enable-threads ***
*** WARNING: you are running uWSGI without its master process manager ***
*** Operational MODE: single process ***
*** uWSGI is running in multiple interpreter mode ***
I've moved the most important points from the comments.
Yep, that's the normal behavior. Nginx's master process needs root privileges to manage listening sockets on the machine. This forum thread states that you can change it, but it may cause problems. However, Nginx does allow to change the owner of the worker processes.
It depends on how the uWSGI was installed. If uWSGI was installed via
apt-get you can start (stop, restart) it
service uwsgi <action>
You installed uWSGI via
pip, so the daemonize option will do
/path/to/uwsgi --daemonize /path/to/logfile
Common sense: do not run uWSGI instances as root. You can start your uWSGIs as root, but be sure to drop privileges with the uid and gid options.
Also take a look at master-as-root option.
You can create as many processes and threads as you want, but it should depend on how many requests you're trying to process (concurrent or per second). You can read about this here. I would try different configurations and choose which one works better.
worker_processes helps to handle concurrent
requests. See this question.
*WARNING: you are running uWSGI without its master process manager*
You didn't specify a
master option in your .ini file. While master
process is certainly unnecessary, it is very useful. It helps to
effectively control workers and respawn them when they die.