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
Related
I know this is a common issue, but due to the fact that I've been searching for 3 hours now, and given that there must be a quantum singularity involved, I had to post this.
I keep getting this familiar error:
[uWSGI] getting INI configuration from uwsgi.ini,
*** Starting uWSGI 2.0.18-debian (64bit) on [Mon May 25 15:56:04 2020] ***,
compiled with version: 8.2.0 on 10 February 2019 02:42:46,
os: Linux-5.6.12-1-MANJARO #1 SMP PREEMPT Sun May 10 14:36:43 UTC 2020,
nodename: a43c6a7bbb2c,
machine: x86_64,
clock source: unix,
pcre jit disabled,
detected number of CPU cores: 8,
current working directory: /srv/myapp,
detected binary path: /usr/bin/uwsgi-core,
setgid() to 33,
setuid() to 33,
your memory page size is 4096 bytes,
detected max file descriptor number: 1048576,
lock engine: pthread robust mutexes,
thunder lock: disabled (you can enable it with --thunder-lock),
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.socket fd 3,
your server socket listen backlog is limited to 100 connections,
your mercy for graceful operations on workers is 60 seconds,
mapped 437520 bytes (427 KB) for 5 cores,
*** Operational MODE: preforking ***,
*** no app loaded. going in full dynamic mode ***,
*** uWSGI is running in multiple interpreter mode ***,
!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!,
no request plugin is loaded, you will not be able to manage requests.,
you may need to install the package for your language of choice, or simply load it with --plugin.,
!!!!!!!!!!! END OF WARNING !!!!!!!!!!,
spawned uWSGI master process (pid: 25),
spawned uWSGI worker 1 (pid: 28, cores: 1),
spawned uWSGI worker 2 (pid: 29, cores: 1),
spawned uWSGI worker 3 (pid: 30, cores: 1),
spawned uWSGI worker 4 (pid: 31, cores: 1),
spawned uWSGI worker 5 (pid: 32, cores: 1),
However, I don't see anything wrong with this very simple setup. My setup:
core/__init__.py
from flask import Flask
def create_app():
app = Flask(__name__)
#app.route('/')
def hello_world():
return 'Hello, World!'
return app
app.py
from core import create_app
app = create_app()
if __name__ == '__main__':
app.run()
Dockerfile
FROM python:3.6-slim
RUN apt-get clean \
&& apt-get -y update
RUN apt-get -y install uwsgi nginx
COPY . /srv/myapp
COPY nginx.conf /etc/nginx
WORKDIR /srv/myapp
RUN pip install -r requirements.txt
RUN chmod +r uwsgi.ini
RUN chmod +x ./start.sh
CMD ["./start.sh"]
start.sh
#!/usr/bin/env bash
service nginx start
uwsgi --ini uwsgi.ini
uwsgi.ini
[uwsgi]
module = app:app
uid = www-data
gid = www-data
master = true
processes = 5
socket = /tmp/uwsgi.socket
chmod-sock = 664
vacuum = true
die-on-term = true
nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;events
{
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
access_log /dev/stdout;
error_log /dev/stdout;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
index index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html;
location /
{
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.socket;
}
}
}
If I add the python3 plugin RUN apt-get -y install uwsgi nginx uwsgi-plugin-python3 in DOCKERFILE and run uwsgi via uwsgi --ini uwsgi.ini --plugin python3 I get:
Traceback (most recent call last):
File "./app.py", line 1, in <module>
from core import create_app
File "./core/__init__.py", line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask'
I don't know if this may be a hint.
Any help is appreciated!
Thanx!
After 8 hours of sleep I found my mistake:
Installing uwsgi via apt-get will not work. It is required to install uwsgi via pip install. (My guess is, that these are two different uwsgi instances / services)
This has been bothering me for hours and have no idea what is going on. When I tried visiting the site through only ip. I get the word internal server error
I get this error log when I restart daemon and uwsgi
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
Set PythonHome to /root/wxr/wxr
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xe0db20
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 437520 bytes (427 KB) for 5 cores
*** Operational MODE: preforking ***
Traceback (most recent call last):
File "./main/wsgi.py", line 10, in <module>
import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
Traceback (most recent call last):
File "/root/wxr/wxr/main/wsgi.py", line 10, in <module>
import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
I do not have virtual environment setup so everything is installed in ubuntu 16.04 directly using root user to setup instead of having additional user
I have this as my server block in site-available
server {
listen 80 default_server;
listen [::]:80 default_server;
# root /var/www/html;
# Add index.php to the list if you are using PHP
# index index.html index.htm index.nginx-debian.html;
server_name _;
location = /favicon.ico { access_log off; log_not_found off; }
location /media {
alias /root/wxr/wxr/mediafiles; # your Django project's media files - amend as required
}
location /static/ {
alias /root/wxr/wxr/static;
}
location / {
include /root/wxr/wxr/uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi/wxr.sock;
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
}
}
my /etc/uwsgi/sites/wxr.ini
[uwsgi]
project = wxr
base =/root
#chdir = %(base)/%(project)/%(project)
#home = %(base)/%(project)/%(project)
wsgi-file = /root/wxr/wxr/main/wsgi.py
chdir = /root/wxr/wxr
home = /root/wxr/wxr
module = main.wsgi:application
master = true
processes = 5
socket = /tmp/uwsgi/%(project).sock
chmod-socket = 666
vacuum = true
enable-threads = true
no-site = true
req-logger = file:/tmp/reqlog
logger = file:/tmp/errlog
my /etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /tmp/uwsgi; chown root:www-data /tmp/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
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 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)