I try to start nginx web server with uwsgi and python django at backend
system ubuntu 12.04
but get 502 Bad Gateway and
-- unavailable modifier requested: 1 --
in logs
my nginx file configs:
server {
listen 80;
server_name site.com;
charset utf-8;
access_log /var/log/nginx/tona-access.log;
error_log /var/log/nginx/tona-error.log;
client_max_body_size 100m;
location /main_media/ {
alias /home/se7en/workspace/tona/main_media/;
expires 30d;
}
location / {
include /etc/nginx/uwsgi_params;
fastcgi_pass unix:///var/tmp/tona_uwsgi.sock;
}
}
my uwsgi start and console outputs:
root#tona:/etc/nginx/sites-enabled# uwsgi --uid www-data --file uwsgi_app.py --plugins python --chdir /home/se7en/workspace/tona/ --pythonpath /home/se7en/workspace/tona/ --module uwsgi_app -c application --limit-as 128 -p 3 -M -s /var/tmp/tona_uwsgi.sock
./python_plugin.so: cannot open shared object file: No such file or directory
*** Starting uWSGI 1.2.5 (32bit) on [Sat Aug 25 16:58:02 2012] ***
compiled with version: 4.6.3 on 24 August 2012 22:03:24
detected number of CPU cores: 1
current working directory: /etc/nginx/sites-enabled
detected binary path: /usr/local/bin/uwsgi
setuid() to 33
limiting address space of processes...
your process address space limit is 134217728 bytes (128 MB)
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/tmp/tona_uwsgi.sock fd 3
Python version: 2.7.3 (default, Aug 1 2012, 05:27:35) [GCC 4.6.3]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x9521058
your server socket listen backlog is limited to 100 connections
*** Operational MODE: preforking ***
added /home/se7en/workspace/tona/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x9521058 pid: 5764 (default app)
mountpoint already configured. skip.
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 5764)
spawned uWSGI worker 1 (pid: 5765, cores: 1)
spawned uWSGI worker 2 (pid: 5766, cores: 1)
spawned uWSGI worker 3 (pid: 5767, cores: 1)
-- unavailable modifier requested: 1 --
-- unavailable modifier requested: 1 --
-- unavailable modifier requested: 1 --
-- unavailable modifier requested: 1 --
my uwsgi_app.py file:
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
you have to set uWSGI in fastcgi mode using --fastcgi-socket instead of -s (that is a shortcut for --socket)
Related
I'm trying to complete the upgrade of my Django project from 1.4 to 1.8. I've got my site running locally without any issues. However when I deploy the upgraded code I get a 502 bad gateway. The site was running on the server using Django 1.4 without any issues.
The 1.4 version of the code was using Gunicorn with Supervisor. I couldn't get the upgraded code to run with Gunicorn so I tried using uWsgi, which resulted in me having the same issue.
I have other sites using Django 1.4 on this same server with are working fine.
I cant really see any useful errors in any logs, the only error I see is in the Nginx log:
2016/02/24 10:32:16 [error] 15475#0: *52 upstream prematurely closed connection while reading response header from upstream, client: [IP address], server: myapp.*, request: "GET /api/get_campaign/ HTTP/1.1", upstream: "http://unix:///var/run/supervised-sockets/myapp-uwsgi.sock:/api/get_campaign/", host: "[site-name]"
Nginx config:
upstream django {
server unix:///var/run/supervised-sockets/myapp-uwsgi.sock;
}
server {
listen 80;
server_name myapp.*;
access_log /var/log/nginx/myapp_access.log;
error_log /var/log/nginx/myapp_error.log notice;
# rewrite URLs of the form static/.*/*.gz to non .gz then gzip_static module will check
# for the compressed version on disk. Round about method to get around django-compressor
# adding the .gz extension
rewrite /static/(.*)\.(css|js)\.gz$ /static/$1.$2 last;
rewrite /media/(.*)\.(css|js)\.gz$ /media/$1.$2 last;
location /static/CACHE/ {
root /srv/myapp/releases/current/myapp/myapp/assets/;
expires max;
break;
}
location /favicon.ico {
root /srv/myapp/releases/current/myapp/myapp/assets/static/img/;
}
location /static/ {
root /srv/myapp/releases/current/myapp/myapp/assets/;
}
location /media/ {
root /srv/myapp/shared/;
}
location / {
uwsgi_pass django;
include /srv/myapp/releases/current/myapp/uwsgi_params;
proxy_set_header HOST $http_host;
#proxy_pass http://unix:/var/run/supervised-sockets/myapp-uwsgi.sock;
proxy_pass http://myapp;
proxy_buffering off; # no need as services are local
proxy_connect_timeout 3000s;
proxy_read_timeout 3000s;
}
This is my uWsgi ini file:
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /srv/myapp/releases/current/myapp
# Django's wsgi file
module = myapp_wsgi:application
# the virtualenv (full path)
home = /srv/myapp/
#virtualenv = myapp
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 2
# the socket (use the full path to be safe
socket = /var/run/supervised-sockets/myapp-uwsgi.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
chown-socket = myapp
# clear environment on exit
vacuum = true
buffer-size=32768
#die-on-term = true
#wsgi-file = myapp/myapp_wsgi.py
When I run uWsgi this is the output:
[uWSGI] getting INI configuration from myapp_uwsgi.ini
*** Starting uWSGI 2.0.12 (64bit) on [Wed Feb 24 10:45:16 2016] ***
compiled with version: 4.6.3 on 22 February 2016 17:10:22
os: Linux-3.2.0-77-virtual #114-Ubuntu SMP Tue Mar 10 17:38:02 UTC 2015
nodename: ip-10-0-9-42
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /srv/myapp/releases/1d4cad9dae00479763636fab34ab2224a59449c4/myapp
detected binary path: /srv/myapp/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /srv/myapp/releases/current/myapp
your processes number limit is 59476
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 socket 0 bound to UNIX address /var/run/supervised-sockets/myapp-uwsgi.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 2.7.3 (default, Dec 18 2014, 19:25:50) [GCC 4.6.3]
Set PythonHome to /srv/myapp/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xf5b420
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 304320 bytes (297 KB) for 2 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xf5b420 pid: 30534 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 30534)
spawned uWSGI worker 1 (pid: 30541, cores: 1)
spawned uWSGI worker 2 (pid: 30542, cores: 1)
This is the Gunicorn config that Supervisor uses:
[program:myapp-gunicorn]
command=/srv/myapp/bin/gunicorn -b unix:/var/run/supervised-sockets/myapp-gunicorn.sock -w 2 myapp_wsgi:application -t 30 --max-requests 600 --timeout 300
numprocs=1
numprocs_start=0
priority=896
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=60
directory=/srv/myapp/releases/current/myapp
user=myapp
redirect_stderr=false
stdout_logfile=/var/log/supervisor/myapp/myapp-gunicorn.out
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
stderr_logfile=/var/log/supervisor/myapp/myapp-gunicorn.err
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=5
This is my Django wsgi file:
import os
import sys
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(THIS_DIR, "/"))
sys.path.insert(0, os.path.join(THIS_DIR, "myapp/apps"))
sys.path.insert(0, os.path.join(THIS_DIR, "myapp/lib"))
os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Any help is really appreciated as I've been looking into this for a while.
Thanks
I changed my uWSGI setup to use the Emperor for multi-app deployment. With the old setup when loading 'mypasswords.pwds' file which was saved right next to my app, there was no issue.
Now running everything with the Emperor I get 'No such file or direcotry' errors. This might be because of my setup or because the Emperor simply works in a different way and I'm not sure what's the case.
Directory Tree:
Project
thisismyapp.py
passwords.pwds
Config for uWSGI Emperor:
[uwsgi]
# Variables
base = /var/www/Project
# Generic Config
home = %(base)/venv
pythonpath = %(base)
socket = /tmp/%n.sock
module = thisismyapp:app # Is this an issue?
logto = /var/log/uwsgi/%n.log
Traceback:
*** Starting uWSGI 2.0.11.2 (64bit) on [Thu Feb 4 00:41:47 2016] ***
compiled with version: 4.9.2 on 24 October 2015 23:42:32
os: Linux-3.19.0-42-generic #48-Ubuntu SMP Thu Dec 17 22:54:45 UTC 2015
nodename: website
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/apps-enabled
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 1868
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 socket 0 bound to UNIX address /tmp/project.sock fd 3
Python version: 2.7.9 (default, Apr 2 2015, 15:37:21) [GCC 4.9.2]
Set PythonHome to /var/www/Project/venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x17355e0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/Project/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x17355e0 pid: 6772 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 6772)
spawned uWSGI worker 1 (pid: 6779, cores: 1)
[pid: 6779|app: 0|req: 1/1] 79.227.145.119 () {46 vars in 967 bytes} [Thu Feb 4 00:41:51 2016] GET / => generated 3552 bytes in 355 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)
announcing my loyalty to the Emperor...
[Errno 2] No such file or directory: 'passwords.pwds'
Python file access:
f = open('passwords.pwds', 'r')
Try this one:
from os import path
passwords_location = path.join(path.dirname(path.realpath(__file__), 'passwords.pwds'))
with open(passwords_location) as f:
do_something()
Your original way using the relative location, so may can't find the file if you're not in the Project folder. Also, use with block is a better way to handle files, it will ensure to close the file when exit the context block.
I'm trying to follow the tutorial at http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html. I've gotten everything working down to http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#using-unix-sockets-instead-of-ports. I am working with an ubuntu 14.4 instance on amazon EC2:
The Nginx config file starts with:
# the upstream component nginx needs to connect to
upstream django {
server unix:///path/to/your/mysite/mysite.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
I am confused about the syntax of setting up a unix socket. I've looked at several sources including http://pymotw.com/2/socket/uds.html , Permission denied - nginx and uwsgi socket and https://serverfault.com/questions/124517/whats-the-difference-between-unix-socket-and-tcp-ip-socket
It looks like they all start with "///" If I understand correctly the path just points to the root directory of ( in my case ) the django project and the path has to end with ".sock" . Does this seem right ?
edit: I've made the uwsgi config file, but I'm trying to run this with the --socket switch instead:
The Nginx config file now starts with:
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/mysite.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
Following what I think you are saying, I'm running uwsgi on socket /tmp/mysite.sock .
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --socket /tmp/mysite.sock --wsgi-file test.py --chmod-socket=664
When I open:
http://52.10.----:8000/
In firefox I see:
502 Bad Gateway
The error log for nginx shows:
2015/03/04 15:08:44 [crit] 18398#0: *3 connect() to unix:///home/ubuntu/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///home/ubuntu/mysite.sock:", host: "52.10.200.38:8000"
edit 2: I commented out the django related stuff -
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
#chdir = /path/to/your/project
# Django's wsgi file
#module = project.wsgi
# the virtualenv (full path)
#home = /path/to/virtualenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 1
# the socket (use the full path to be safe
socket = /tmp/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
# clear environment on exit
vacuum = true
I tried:
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file test.py
but got a 502 error again.
2015/03/04 17:50:00 [crit] 18842#0: *1 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.200.38:8000"
EDIT 3:
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file te
st.py
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 18:41:43 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 !!!
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 socket 0 bound to UNIX address /tmp/mysite.sock 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 0x205e710
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x205e710 pid: 18868 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 18868)
spawned uWSGI worker 1 (pid: 18869, cores: 1)
edit 4: - just noticed
♥SIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
goodbye to uWSGI.
VACUUM: unix socket /tmp/mysite.sock removed.
So everytime I exit uWSGI, the socket is being removed. Maybe I should turn the vaccum option off so the chmod settings are preserved?
I changed:
vacuum = false
but...
(env1)ubuntu#ip-172-31-28-196:/tmp$ sudo chmod 777 mysite.sock
(env1)ubuntu#ip-172-31-28-196:/tmp$ ls -la
total 8
drwxrwxrwt 2 root root 4096 Mar 4 19:32 .
drwxr-xr-x 22 root root 4096 Mar 4 19:06 ..
srwxrwxrwx 1 ubuntu ubuntu 0 Mar 4 19:32 mysite.sock
(env1)ubuntu#ip-172-31-28-196:/tmp$ cd /home/ubuntu/
(env1)ubuntu#ip-172-31-28-196:~$ ls
host_type.py requirements.txt test.py tproxy
(env1)ubuntu#ip-172-31-28-196:~$ sudo /etc/init.d/nginx restart
* Restarting nginx nginx
...done.
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-fi
st.py
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 19:36:42 2015] ***
.....
spawned uWSGI worker 1 (pid: 1568, cores: 1)
♥SIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
goodbye to uWSGI.
(env1)ubuntu#ip-172-31-28-196:~$ cd /tmp
(env1)ubuntu#ip-172-31-28-196:/tmp$ ls -la
total 8
drwxrwxrwt 2 root root 4096 Mar 4 19:36 .
drwxr-xr-x 22 root root 4096 Mar 4 19:06 ..
srw-rw-r-- 1 ubuntu ubuntu 0 Mar 4 19:36 mysite.sock
so chmod is not preserved..
edit 5:
(env1)ubuntu#ip-172-31-28-196:/tmp$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file
test.py --chmod-socket=777
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 20:54:21 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: /tmp
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
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 socket 0 bound to UNIX address /tmp/mysite.sock 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 0x18b4790
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 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 master process (pid: 1858)
spawned uWSGI worker 1 (pid: 1859, cores: 1)
--- no python application found, check your startup logs for errors ---
[pid: 1859|app: -1|req: -1/1] 64.56.60.130 () {36 vars in 555 bytes} [Wed Mar 4 20:54:34 2015] GET
/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
Now getting internal server error:
2015/03/04 19:33:26 [crit] 1531#0: *1 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.200.38:8000"
Change it to say server unix:///tmp/mysite.sock; and then in the uwsgi ini file you make, create the unix socket in /tmp/
I have been trying to read everything I can find concerning this issue (and have learned much while doing so). The closest link I could find is here and here. My issue is almost identical except I'm running uwsgi exclusively in emperor mode. When I run uswsgi services WITHOUT running it in emperor mode my django website runs just fine. No matter how I change my configuration I always get the error message my /tmp/uwsgi.log file: "--- no python application found, check your startup logs for errors ---" I have listed my configuration and error log below:
OS version: Linux raspberrypi 3.6.11+ #538 armv6l GNU/Linux
Django version: 1.6.5
uwsgi version: 2.0.5.1
Virtual environment: /var/www/testbed/env
Project location: /var/www/testbed/project/auth
project tree:
./auth/
|-- __init__.py
|-- __init__.pyc
|-- requirements.txt
|-- settings.py
|-- settings.pyc
|-- urls.py
|-- urls.pyc
|-- wsgi.py
`-- wsgi.pyc
file wsgi.py:
"""
WSGI config for auth project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os, sys, site
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
sys.path.append('/usr/lib/python2.7')
sys.path.append('/usr/lib/python2.7/dist-packages')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "auth.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
file /etc/uwsgi/emperor.ini:
[uwsgi]
master = true
emperor = /etc/uwsgi/vassals
logto = /tmp/uwsgi.log
file /etc/uwsgi/vessals/auth.ini:
[uwsgi]
#plugins = python
# Django-related settings
chdir =/var/www/testbed/project/auth
module = auth.wsgi:application
# the virtualenv (full path)
home =/var/www/testbed/env
virtualenv =/var/www/testbed/env
# process-related settings
enable-threads = true
pythonpath = /var/www/testbed/project/auth
#wsgi-file = /var/www/testbed/project/auth/auth/wsgi.py
env = DJANGO_SETTINGS_MODULE=auth.settings
mount = /testbed/auth/admin=/var/www/testbed/project/auth/auth/wsgi.py
manage-script-name = true
#route-run = log:SCRIPT_NAME=${SCRIPT_NAME}
# maximum number of worker processes
processes = 1 #Simple rule is # of cores on machine
# the socket (use the full path to be safe
socket = /var/www/testbed/project/auth/uwsgi.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
# clear environment on exit
vacuum = true
logto = /tmp/uwsgi.log
Command being executed listed below:
/var/www/testbed/env/bin/uwsgi --ini /etc/uwsgi/emperor.ini --emperor /etc/uwsgi/vassals/ --http :8000 --plugin python --binary-pathusr/local/bin/uwsgi
Error file /tmp/uwsgi.log:
*** Starting uWSGI 2.0.5.1 (32bit) on [Tue Jun 10 19:06:12 2014] ***
compiled with version: 4.6.3 on 10 June 2014 01:41:52
os: Linux-3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013
nodename: raspberrypi
machine: armv6l
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your processes number limit is 3376
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 6
*** starting uWSGI Emperor ***
uwsgi socket 0 bound to TCP address 127.0.0.1:57524 (port auto-assigned) fd 5
Python version: 2.7.3 (default, Mar 18 2014, 05:13:23) [GCC 4.6.3]
*** has_emperor mode detected (fd: 8) ***
[uWSGI] getting INI configuration from auth.ini
*** Starting uWSGI 2.0.5.1 (32bit) on [Tue Jun 10 19:06:12 2014] ***
compiled with version: 4.6.3 on 09 June 2014 23:07:00
os: Linux-3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013
nodename: raspberrypi
machine: armv6l
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your processes number limit is 3376
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 socket 0 bound to UNIX address /var/www/testbed/project/auth/uwsgi.sock fd 3
Python version: 2.7.3 (default, Mar 18 2014, 05:13:23) [GCC 4.6.3]
Set PythonHome to /var/www/testbed/env
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1dca830
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 128512 bytes (125 KB) for 1 cores
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 23068)
spawned uWSGI worker 1 (pid: 23071, cores: 1)
spawned uWSGI http 1 (pid: 23072)
Python main interpreter initialized at 0x616918
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 128512 bytes (125 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/testbed/project/auth/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x616918 pid: 23070 (default app)
mounting /var/www/testbed/project/auth/auth/wsgi.py on /testbed/auth/admin
added /var/www/testbed/project/auth/ to pythonpath.
WSGI app 1 (mountpoint='/testbed/auth/admin') ready in 3 seconds on interpreter 0x9c6218 pid: 23070
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 23070)
Tue Jun 10 19:06:18 2014 - [emperor] vassal auth.ini has been spawned
spawned uWSGI worker 1 (pid: 23073, cores: 1)
Tue Jun 10 19:06:18 2014 - [emperor] vassal auth.ini is ready to accept requests
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/1] 192.168.1.6 () {38 vars in 742 bytes} [Tue Jun 10 19:07:11 2014] GET /testbed/auth/admin => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/2] 192.168.1.6 () {36 vars in 626 bytes} [Tue Jun 10 19:07:11 2014] GET /favicon.ico => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/3] 192.168.1.6 () {38 vars in 742 bytes} [Tue Jun 10 19:07:13 2014] GET /testbed/auth/admin => generated 21 bytes in 2 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 23071|app: -1|req: -1/4] 192.168.1.6 () {36 vars in 626 bytes} [Tue Jun 10 19:07:13 2014] GET /favicon.ico => generated 21 bytes in 1 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
At this point, I'm grasping at straws. Out of all the reading that I have done I can't see why this keeps rendering the "Internal Server Error." I may have over looked something that why I've finally given in to my pride by posting my sorrows here. Since I've gotten this far I really do think that I have overlooked something very small. Any help would be greatly appreciated.
I had this issue several times in my deployments with usgi-emperor an the problem was that I didn't set the correct ALLOWED_HOSTS in my Django's project config file
In your config you shold have
ALLOWED_HOSTS=[ "yourdomain.com", "other.domain.com" ]
or this (discouraged because of security concerns, use at your own risk):
ALLOWED_HOSTS=["*"]
to allow any host
https://docs.djangoproject.com/en/1.8/ref/settings/#allowed-hosts
I've tried some uwsgi tutorials but can't get a simple python script to run in my browser.
Ive read through this (http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html) and this (https://www.digitalocean.com/community/articles/how-to-deploy-python-wsgi-applications-using-uwsgi-web-server-with-nginx) and others, but for some reason can't get a simple uwsgi app running. I am currently not going through a web server, just uwsgi by itself.
I have the following wsgi.py:
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ["Hello!"]
and I run:
uwsgi --socket 127.0.0.1:8080 --chdir /my/program/path --pp .. -w wsgi
which produces the following output (looks promising):
*** Starting uWSGI 2.0.3 (64bit) on [Mon Apr 14 12:51:32 2014] ***
compiled with version: 4.6.3 20120306 (Red Hat 4.6.3-2) on 14 April 2014 12:01:33
os: Linux-3.1.0-7.fc16.x86_64 #1 SMP Tue Nov 1 21:10:48 UTC 2011
nodename: ip-10-252-98-215
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /usr/oai/icscada/www
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 1024
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 socket 0 bound to TCP address 127.0.0.1:8080 fd 3
Python version: 2.7.3 (default, Jul 24 2012, 11:41:40) [GCC 4.6.3 20120306 (Red Hat 4.6.3-2)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x2504ee0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72752 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added ../ to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x2504ee0 pid: 21702 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 21702, cores: 1)
but when I go to port 8080 from my browser I get a "could not connect" error. Port 8080 is open and has been tested.
I've also tried the following wsgi.py:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
exactly the same results
If you want to run uWSGI without a web server in front of it, use http option instead of socket. See Native HTTP support.
Also, use 0.0.0.0:80 as an address if you are accessing from a remote machine.