I'm trying to follow the tutorial at http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html. Following the directions I have:
(env1)ubuntu#ip-172-31-**-**:~/tproxy/tp$ uwsgi --http :8000 --wsgi-file test.py
*** Starting uWSGI 2.0.9 (64bit) on [Tue Mar 3 11:25:12 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-**-**
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/tproxy/tp
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7862
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 11221)
uwsgi socket 0 bound to TCP address 127.0.0.1:55522 (port auto-assigned) fd 3
Python version: 3.4.0 (default, Apr 11 2014, 13:08:40) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x786830
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
failed to open python file test.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 11220, cores: 1)
Since I'm on an ec2 ubuntu instance I tried the opening public and private ips at port 8000, eg http://172.31..*:8000/ , but the request times out. What am I doing wrong?
edit: I tried to make the changes you suggested. Here is the output:
(env1)ubuntu#ip-172-31-28-196:~$ ls
host_type.py requirements.txt test.py tproxy
(env1)ubuntu#ip-172-31-28-196:~$ sudo chmod 666 test.py
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --http :8000 --wsgi-file test.py
*** Starting uWSGI 2.0.9 (64bit) on [Tue Mar 3 14:45:58 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-28-196
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7862
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
probably another instance of uWSGI is running on the same address (:8000).
bind(): Address already in use [core/socket.c line 764]
(env1)ubuntu#ip-172-31-28-196:~$ ls -la
total 60
drwxr-xr-x 7 ubuntu ubuntu 4096 Mar 3 03:03 .
drwxr-xr-x 3 root root 4096 Feb 20 22:20 ..
-rw------- 1 ubuntu ubuntu 1554 Mar 3 11:35 .bash_history
-rw-r--r-- 1 ubuntu ubuntu 220 Apr 9 2014 .bash_logout
-rw------- 1 ubuntu ubuntu 3751 Feb 27 19:49 .bashrc
drwx------ 3 ubuntu ubuntu 4096 Feb 27 21:08 .cache
-rw-rw-r-- 1 ubuntu ubuntu 0 Feb 23 17:15 host_type.py
drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 25 18:02 .pip
-rw-r--r-- 1 ubuntu ubuntu 675 Apr 9 2014 .profile
-rw-rw-r-- 1 ubuntu ubuntu 73 Mar 2 02:35 requirements.txt
drwx------ 2 ubuntu ubuntu 4096 Feb 20 22:20 .ssh
-rw-rw-rw- 1 root root 136 Mar 3 03:02 test.py
drwxrwxr-x 3 ubuntu ubuntu 4096 Mar 2 18:33 tproxy
-rw------- 1 ubuntu ubuntu 4119 Feb 27 19:51 .viminfo
drwxrwxr-x 3 ubuntu ubuntu 4096 Feb 28 02:17 .virtualenvs
(env1)ubuntu#ip-172-31-28-196:~$
It couldn't find test.py. Make sure it has permissions to the file. Did you make your virtuslenv with sudo? If so do a chmod and change the folder permissions to something your nginx and uwsgi has access to. Or it could be the path to the test.py file us wrong, double check that.
Related
I have been struggling to deploy a flask app to my server using uWSGI in
Emperor mode all day and am at a loss why it is not working. I have read all the other uWSGI Emperor mode questions here & asked on #uwsgi & the mailing list with no reply.
My setup is nginx (1.4.6-1ubuntu3.2), uWSGI==2.0.10 installed via pip
into a virtualenv, Flask==0.10.1, and Python 3.4.0. supervisord is
responsible for launching the Emperor process.
The flask app itself works fine when I start it manually bound to a TCP port, and when I manually run uwsgi like:
uwsgi -s /tmp/oauthsvc.sock -w wsgi --stats /tmp/oauthsvc-stats.sock
I do notice that even though I think I configured the vassal to use a
unix socket, it reports on startup that it is listening to http://127.0.0.1:5000/
I verified with strace that nginx is opening the socket, and permissions
of that socket are 777:
srwxrwxrwx 1 oauthsvc oauthsvc 0 Jun 3 18:34 /tmp/oauthsvc.sock
srwxrwxrwx 1 oauthsvc oauthsvc 0 Jun 3 18:08 /tmp/oauthsvc-stats.sock
But the connection eventually just times out.
My configs & some log output follows.
The nginx config is as simple as can be:
server {
listen 80;
server_name default;
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/oauthsvc.sock;
}
}
supervisor launches the emporer process with this command:
[program:oauthsvc-emperor]
command=/services/oauthsvc/services/oauthsvc/bin/uwsgi --emperor /services/oauthsvc/etc/uwsgi/vassals --die-on-term --uid 1005 --gid 1005 --logto /services/oauthsvc/var/log/uwsgi/emperor.log
user=oauthsvc
autostart=true
autorestart=true
redirect_stderr=true
The vassal's ini file looks like:
[uwsgi]
# do not turn on master mode when spawned by emperor
# http://stackoverflow.com/questions/15055002/uwsgi-master-with-emperor-spawns-two-emperors
#master = true
protocol = uwsgi
socket = /tmp/oauthsvc.sock
stats = /tmp/oauthsvc-stats.sock
daemonize = /services/oauthsvc/var/log/uwsgi/oauthsvc.log
chdir = /services/oauthsvc/services/oauthsvc/oauthsvc-server
wsgi-file = wsgi.py
callable = app
chmod-socket = 777
uid = 1005
gid = 1005
virtualenv = /services/oauthsvc/services/oauthsvc
# PYTHONHOME
home = /services/oauthsvc/services/oauthsvc
#env =
processes = 4
vacuum = true
# If you start uWSGI without threads, the Python GIL will not be enabled, so
# threads generated by your application will never run unless you include:
enable-threads = true
harakiri = 30
And finally, wsgi.py:
#!/usr/bin/env python3
from oauthsvc.flask.server import parse_args, configured_app
args = parse_args()
app = configured_app(args.config, debug=args.debug)
app.run()
The emperor log:
*** Starting uWSGI 2.0.10 (64bit) on [Wed Jun 3 18:34:25 2015] ***
compiled with version: 4.8.2 on 03 June 2015 18:32:12
os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
nodename: ip-10-0-1-224
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /
detected binary path: /services/oauthsvc/src/bs-oauth-svc.2015-06-03.183113/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 30038
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from oauthsvc.ini
The vassal log:
*** Starting uWSGI 2.0.10 (64bit) on [Wed Jun 3 18:34:25 2015] ***
compiled with version: 4.8.2 on 03 June 2015 18:32:12
os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
nodename: ip-10-0-1-224
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /services/oauthsvc/etc/uwsgi/vassals
detected binary path: /services/oauthsvc/src/bs-oauth-svc.2015-06-03.183113/bin/uwsgi
chdir() to /services/oauthsvc/services/oauthsvc/oauthsvc-server
your processes number limit is 30038
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/oauthsvc.sock fd 3
Python version: 3.4.0 (default, Apr 11 2014, 13:08:40) [GCC 4.8.2]
Set PythonHome to /services/oauthsvc/services/oauthsvc
Python main interpreter initialized at 0x135d4d0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 363840 bytes (355 KB) for 4 cores
*** Operational MODE: preforking ***
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Brian on the uWSGI mailing list solved this for me. The answer is: don't call app.run() in the wsgi.py file! I knew it would be something embarrassing.
when i start it without emperor it works:
uwsgi --ini /etc/uwsgi/vassals/uwsgi.conf --uid books --gid books
But when i use emperor mode it freezes:
uwsgi --emperor /etc/uwsgi/vassals --uid books --gid books
And give such response:
*** Starting uWSGI 2.0.1 (64bit) on [Fri Oct 24 10:47:46 2014] ***
compiled with version: 4.8.2 20140120 (Red Hat 4.8.2-16) on 24 October 2014 10:36:47
os: Linux-3.10.0-123.8.1.el7.x86_64 #1 SMP Mon Sep 22 19:06:58 UTC 2014
nodename: essenly.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/bin/uwsgi
setgid() to 1000
setuid() to 1000
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3839
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
Thanks for your help.
UPDATE. Ignore my advice regarding master. Doc says that emperor mode should not be used with master normally. http://uwsgi-docs.readthedocs.org/en/latest/Emperor.html#notes
Try to run emperor with master process. Add master = true to your ini file and run uwsgi as root. Workers will downgrade to non-priviledged user (if specified)
I've seen at least 3 questions about this problem.
Virtualenv (Python 3.2)
Django project in this env
uWSGI
But I have plugins = python3 in uWSGI settings file and it's ok!
Server is started, everything is working...
Restart server - and everything is still working...
Reload server (or touch reload-file) and you have this error:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named encodings
Even more... I have another project in another Env and touch reload-file works for it.
Any suggestions why can this happen?
PS: I tried to create a new virtualenv
Logs:
After service uwsgi restart:
...
Sun Dec 29 22:57:21 2013 - detected max file descriptor number: 1024
Sun Dec 29 22:57:21 2013 - lock engine: pthread robust mutexes
Sun Dec 29 22:57:21 2013 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/test/socket fd 3
Sun Dec 29 22:52:59 2013 - uwsgi socket 1 bound to TCP address 127.0.0.1:3045 fd 5
Sun Dec 29 22:52:59 2013 - Python version: 3.2.3 (default, Sep 25 2013, 19:38:45) [GCC 4.7.2]
Sun Dec 29 22:52:59 2013 - Set PythonHome to /pyenvs/test/
Sun Dec 29 22:52:59 2013 - Python main interpreter initialized at 0x688cc0
Sun Dec 29 22:52:59 2013 - threads support enabled
Sun Dec 29 22:52:59 2013 - your server socket listen backlog is limited to 10000 connections
Sun Dec 29 22:52:59 2013 - *** Operational MODE: preforking ***
Sun Dec 29 22:52:59 2013 - WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x688cc0 pid: 1619 (default app)
Sun Dec 29 22:52:59 2013 - *** uWSGI is running in multiple interpreter mode ***
Sun Dec 29 22:52:59 2013 - spawned uWSGI master process (pid: 1619)
Sun Dec 29 22:52:59 2013 - spawned uWSGI worker 1 (pid: 1628, cores: 1)
Sun Dec 29 22:52:59 2013 - spawned uWSGI worker 2 (pid: 1629, cores: 1)
After service uwsgi reload:
Sun Dec 29 22:55:31 2013 - *** Starting uWSGI 1.2.3-debian (64bit) on [Sun Dec 29 22:55:31 2013] ***
...
Sun Dec 29 22:55:31 2013 - detected max file descriptor number: 1024
Sun Dec 29 22:55:31 2013 - lock engine: pthread robust mutexes
Sun Dec 29 22:55:31 2013 - uwsgi socket 0 inherited UNIX address /run/uwsgi/app/test/socket fd 3
Sun Dec 29 22:55:31 2013 - uwsgi socket 1 inherited INET address 127.0.0.1:3045 fd 5
Sun Dec 29 22:55:31 2013 - Python version: 3.2.3 (default, Sep 25 2013, 19:38:45) [GCC 4.7.2]
Sun Dec 29 22:55:31 2013 - Set PythonHome to /pyenvs/test/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named encodings
Update 1
It is definitely virtual env. Copying my old VEnv and using didn't cause this problem.
Still have no idea why a newly created one doesn't work.
Copying only python executable didn't help.
I don't know exactly what happened since I did a lot of things:
System upgrade
New python environment
Python version 3.3, not 3.2
uwsgi 1.2.4 system package (perhaps this helped)
or better use pip install uwsgi in your VE and run what you need with supervisord
Now it's working. Thanks roberto.
So I have the following configuration:
Nginx server with uWsgi
Django project in a virtualenv
My virtualenv is owned by an ordinal system user and the whole configuration works fine!
The uwsgi process is configured to run with nginx uid & gid, as well as the nginx process owner in the nginx.conf.
But, if I try to use another virtualenv satisfying the same requirements, but owned by root, my uwsgi can't locate the virtualenv, throwing an import error.
Is this normal and is my aproach correct to use a root owned virtualenv?
Edit:
uwsgi config:
[uwsgi]
virtualenv = /root/Envs/rootenv
thread = 4
uid = nginx
gid = nginx
env = DJANGO_SETTINGS_MODULE=myServer.settings
module = django.core.handlers.wsgi:WSGIHandler()
chdir = /var/www/myServer
socket = /var/run/uwsgi/myserver.sock
logto = /var/log/uwsgi/myserver.log
/root/.bashrc:
### Virtualenv settings ###
export WORKON_HOME=/root/Envs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
uwsgi log traceback:
*** Starting uWSGI 1.9.15 (64bit) on [Fri Sep 6 14:02:41 2013] ***
compiled with version: 4.7.2 on 06 September 2013 10:59:26
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
nodename: myserver3
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /
detected binary path: /usr/local/bin/uwsgi
setgid() to 32
set additional group 4 (adm)
setuid() to 32
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7929
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
Python version: 2.7.3 (default, Jan 2 2013, 14:09:21) [GCC 4.7.2]
Set PythonHome to /root/Envs/rootenv
ImportError: No module named site
*** Starting uWSGI 1.9.15 (64bit) on [Fri Sep 6 14:03:13 2013] ***
compiled with version: 4.7.2 on 06 September 2013 10:59:26
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
nodename: myserver3
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /
detected binary path: /usr/local/bin/uwsgi
setgid() to 32
set additional group 4 (adm)
setuid() to 32
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7929
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
Python version: 2.7.3 (default, Jan 2 2013, 14:09:21) [GCC 4.7.2]
Set PythonHome to /root/Envs/rootenv
ImportError: No module named site
I am running a django app with nginx and uwsgi. It was was working ok but suddenly I do not know what I changed that the app stop working.
The problem resides in that python version from uWsgi is 2.4.3 which is the default version in Linux CentOs and I have installed django, webpy and other python distributions in version 2.7.3 (will upgrade sooner)
I also tried creating a symbolic link from python 2.7 path to just "python" in usr/bin
and did not work.
How can I make uWsgi use python2.7.3(/usr/local/bin/) instead of 2.4.3?
Django ini:
socket = 127.0.0.1:3031
master = true
processes = 4
env = DJANGO_SETTINGS_MODULE=djtest.settings
module = django.core.handlers.wsgi:WSGIHandler()
When I initialize
./uwsgi --ini django.ini
[uWSGI] getting INI configuration from django.ini
*** Starting uWSGI 1.3 (64bit) on [Sat Nov 24 00:27:55 2012] ***
compiled with version: 4.1.2 20080704 (Red Hat 4.1.2-52) on 23 November 2012 22:37:39
os: Linux-2.6.18-194.17.4.el5xen #1 SMP Mon Oct 25 16:36:31 EDT 2010
nodename: v238545.hostingator.net
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /root
detected binary path: /opt/uwsgi/uwsgi
your processes number limit is 32832
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 5841)
uwsgi socket 0 bound to TCP address 127.0.0.1:59395 (port auto-assigned) fd 3
Python version: 2.4.3 (#1, Jun 18 2012, 08:55:23) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1cc1130
your server socket listen backlog is limited to 100 connections
mapped 72352 bytes (70 KB) for 1 cores
*** Operational MODE: single process ***
added /usr/local/bin/ to pythonpath.
added /home/indaxone/serv/ to pythonpath.
ImportError: No module named django.core.handlers.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 5840, cores: 1)
Before doing the "make" during the uwsgi installation I did the following:
python2.7 uwsgiconfig.py --build