NGINX with uwsgi and django connection refused - django

Welcome stackoverflowers. I`ve been fighting with setting up nginx with uwsgi with django app... There has to be a small mistake somewhere but I cant find it. Here is my file from pastebin, containing files directly related to my issue and also a console log. I would be very greateful if somebody could take a look and help me out.
artcolor_uwsgi.ini file
[uwsgi]
chdir = /home/seb/pypassion/artcolor/src/
module = artcolor.wsgi
home = /home/seb/pypassion/artcolor/artcolor_venv/
master = true
processes = 10
socket = /home/seb/pypassion/artcolor/src/artcolor.sock
#http-socket = :8001
#vacuum = true
artcolor_nginx.conf file
upstream django {
server /home/seb/pypassion/artcolor/src/artcolor.sock; # for a file socket
#server 127.0.0.1:8001;
}
# configuration of the server
server {
# the port your site will be served on
listen 8001;
server_name localhost; # substitute your machine's IP address or FQDN
charset utf-8;
access_log /home/seb/pypassion/artcolor/logs/nginx-access.log;
error_log /home/seb/pypassion/artcolor/logs/nginx-error.log;
# max upload size
client_max_body_size 1G; # adjust to taste
# Django media
location /media/ {
alias /home/seb/pypassion/artcolor/src/media/; # your Django project's media files - amend as required
}
location /static/ {
alias /home/seb/pypassion/artcolor/src/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
wsgi.py file
import os
import sys
sys.path.append("/home/seb/pypassion/artcolor/src/")
sys.path.append("/home/seb/pypassion/artcolor/src/artcolor/")
sys.path = sys.path[::-1]
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "artcolor.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
my console
(artcolor_venv)seb#debian:~/pypassion/artcolor/src$ uwsgi --ini artcolor_uwsgi.ini
[uWSGI] getting INI configuration from artcolor_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Fri Feb 27 11:48:45 2015] ***
compiled with version: 4.7.2 on 27 February 2015 11:00:34
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2
nodename: debian
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /home/seb/pypassion/artcolor/src
detected binary path: /home/seb/pypassion/artcolor/artcolor_venv/bin/uwsgi
chdir() to /home/seb/pypassion/artcolor/src/
your processes number limit is 63796
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 /home/seb/pypassion/artcolor/src/artcolor.sock fd 3
Python version: 2.7.3 (default, Mar 13 2014, 11:26:58) [GCC 4.7.2]
Set PythonHome to /home/seb/pypassion/artcolor/artcolor_venv/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x20e9d30
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 800448 bytes (781 KB) for 10 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x20e9d30 pid: 14848 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 14848)
spawned uWSGI worker 1 (pid: 14849, cores: 1)
spawned uWSGI worker 2 (pid: 14850, cores: 1)
spawned uWSGI worker 3 (pid: 14851, cores: 1)
spawned uWSGI worker 4 (pid: 14852, cores: 1)
spawned uWSGI worker 5 (pid: 14853, cores: 1)
spawned uWSGI worker 6 (pid: 14854, cores: 1)
spawned uWSGI worker 7 (pid: 14855, cores: 1)
spawned uWSGI worker 8 (pid: 14856, cores: 1)
spawned uWSGI worker 9 (pid: 14857, cores: 1)
spawned uWSGI worker 10 (pid: 14858, cores: 1)
SOLVED
I linked my nginx file to sites-available not as I was supossed to sites-enabled

SOLUTION:
I managed to resolve problem.
The reason was wrong linking the nginx.conf file.
I accidently linked in to sites-available, not as I was supposed to sites-enabled
Thanks

Related

No module named 'django' uWSGI

in a nutshell I am getting the following error message from uWSGI when I try to test my installation against the examples found here:
$ uwsgi --socket 127.0.0.1:3031 --chdir /home/user/~Env/proj0/proj0 --wsgi-file wsgi.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191
*** Starting uWSGI 2.0.15 (64bit) on [Wed May 31 14:10:35 2017] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-11) on 30 May 2017 20:50:53
os: Linux-3.10.0-514.10.2.el7.x86_64 #1 SMP Fri Mar 3 00:04:05 UTC 2017
nodename: echo.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/user/~Env
detected binary path: /usr/local/bin/uwsgi
chdir() to /home/user/~Env/proj0/proj0
your processes number limit is 4096
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:3031 fd 3
Python version: 3.6.1 (default, May 29 2017, 14:21:37) [GCC 4.8.5 20150623
(Red Hat 4.8.5-11)]
Python main interpreter initialized at 0x1639580
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 415360 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
Traceback (most recent call last):
File "wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
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: 20065)
spawned uWSGI worker 1 (pid: 20066, cores: 2)
spawned uWSGI worker 2 (pid: 20067, cores: 2)
spawned uWSGI worker 3 (pid: 20068, cores: 2)
spawned uWSGI worker 4 (pid: 20069, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 15 ***
So obviously it found my wsgi.py file, but not Django. I'm not sure if I screwed up installing uWSGI system wide, my virtualenv folder layout, or whatever. I had wanted to deploy my app soon, but this takes precedence since I want to use nginx and uWSGI. My directory structure:
~Env---
projectenv proj0
bin proj0
include __init__.py
libs __pycache__
. settings.py
urls.py
views.py
wsgi.py
Any help at this point would be great. Thanks.
It doesn't look like it's using a Python interpreter that has Django installed, so it's probably not seeing your virtualenv.
Did you take the appropriate step to add your virtualenv to uwsgi options?
https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#virtualenvs

Issue using supervisor and uwsgi in conda env

I'm trying to run a Flask app with uwsgi + supervisor + nginx.
uwsgi is installed in a conda env, and I can run my app with no issue without supervisor, i.e. if I run (with my conda env activated):
uwsgi --ini /home/me/Development/flask/myflaskapp/myflaskapp.ini
with the following config:
/home/me/Development/flask/myflaskapp/myflaskapp.ini
[uwsgi]
chmod-socket = 666
socket = /home/me/Development/flask/myflaskapp/run/myflaskapp.sock
module = wsgi
callable = app
vim /etc/nginx/sites-available/myflaskapp
server {
listen 8000;
server_name localhost;
client_max_body_size 50M;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/me/Development/flask/myflaskapp/run/myflaskapp.sock;
}
}
Now I create a supervisor config file:
/etc/supervisor/conf.d/uwsgi-myflaskapp.conf
[program:uwsgi-myflaskapp]
command=/home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi /home/me/Development/flask/myflaskapp/myflaskapp.ini
autostart=true
autorestart=true
stdout_logfile=/home/me/Development/flask/myflaskapp/log/uwsgi-myflaskapp.log
redirect_stderr=true
exitcodes=0
I start supervisor (installed system-wide) with
sudo service supervisor start
and load the conf file with
sudo supervisorctl reload
but I get the following error in the log file:
ImportError: No module named wsgi
Any suggestion?
Here's the complete log:
[uWSGI] getting INI configuration from /home/me/Development/flask/myflaskapp/myflaskapp.ini
*** Starting uWSGI 2.0.12 (64bit) on [Mon Jan 11 19:12:14 2016] ***
compiled with version: 4.8.4 on 11 January 2016 10:54:59
os: Linux-3.13.0-74-generic #118-Ubuntu SMP Thu Dec 17 22:52:10 UTC 2015
nodename: roquefort
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /
detected binary path: /home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi
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 63047
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 /home/me/Development/flask/myflaskapp/run/myflaskapp.sock fd 3
Python version: 2.7.11 |Continuum Analytics, Inc.| (default, Dec 6 2015, 18:08:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x18001e0
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 ***
ImportError: No module named 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: 24671, cores: 1)
I added the the path of the wsgi.py file in /home/me/Development/flask/myflaskapp/myflaskapp.ini with
chdir = /home/me/Development/flask/myflaskapp
so that it can now find wsgi.

uwsgi socket file not created

I am having trouble setting up server using uwsgi and nginx. This is my uwsgi ini file (and symlink in vassals):
# ebook_uwsgi.ini file
[uwsgi]
#emperor = /etc/uwsgi/vassals
#plugins = python #if uwsgi installed with pip, dont have to use this line
# Django-related settings
# the base directory (full path)
chdir = /var/www/django/ebook/ebook/wsgi/ebook/
# Django's wsgi file
module = controller.wsgi:application
# the virtualenv (full path)
home = /var/www/django/ebook
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /var/uwsgi/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
uid = www-data
gid = www-data
# clear environment on exit
vacuum = true
no-site = True
wsgi-file = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
#env = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable
and this is my nginx conf file:
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///var/uwsgi/ebook.sock; # for a file socket
#server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name IP; #www.domain.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/django/ebook/ebook/data; # your Django project's media files - amend as required
}
location /static {
alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
include /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
}
}
When I run uwsgi as my user(lucas03)
uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
this is output:
*** Starting uWSGI 2.0.10 (64bit) on [Tue May 12 20:43:19 2015] ***
compiled with version: 4.7.2 on 14 April 2015 16:47:40
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /var
detected binary path: /usr/local/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 2062113
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 ebook_uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Tue May 12 20:43:19 2015] ***
compiled with version: 4.7.2 on 14 April 2015 16:47:40
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/local/bin/uwsgi
chdir() to /var/www/django/ebook/ebook/wsgi/ebook/
your processes number limit is 2062113
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/uwsgi/ebook.sock fd 3
Python version: 2.7.3 (default, Mar 13 2014, 11:26:58) [GCC 4.7.2]
Set PythonHome to /var/www/django/ebook
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xea41a0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 800448 bytes (781 KB) for 10 cores
*** Operational MODE: preforking ***
virtualenv is active
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xea41a0 pid: 6291 (default app)
mountpoint already configured. skip.
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 6291)
Tue May 12 20:43:19 2015 - [emperor] vassal ebook_uwsgi.ini has been spawned
spawned uWSGI worker 1 (pid: 6292, cores: 1)
spawned uWSGI worker 2 (pid: 6293, cores: 1)
Tue May 12 20:43:19 2015 - [emperor] vassal ebook_uwsgi.ini is ready to accept requests
spawned uWSGI worker 3 (pid: 6294, cores: 1)
spawned uWSGI worker 4 (pid: 6295, cores: 1)
spawned uWSGI worker 5 (pid: 6296, cores: 1)
spawned uWSGI worker 6 (pid: 6297, cores: 1)
spawned uWSGI worker 7 (pid: 6298, cores: 1)
spawned uWSGI worker 8 (pid: 6299, cores: 1)
spawned uWSGI worker 9 (pid: 6300, cores: 1)
spawned uWSGI worker 10 (pid: 6301, cores: 1)
ebook.sock is created:
drwxrwxr-x 2 www-data www-data 3 máj 12 20:43 .
drwxr-xr-x 13 root root 15 apr 14 16:29 ..
srw-rw-r-- 1 lucas03 lucas03 0 máj 12 20:43 ebook.sock
but I get 502 Bad Gateway. So I change owner of ebook.sock to www-data sudo chown www-data:www-data ebook.sock, my website is loaded correctly. Well, I thought it was great. Now I just need to run uwsgi so that it can create ebook.sock as user www-data.
So I set uwsgi to start on startup, I edited /etc/rc.local.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
exit 0
However, after I restart server, file ebook.sock is not created at all, although uwsgi runs. (I can see it in ps aux | grep uwsgi). So I thought that it is run same or similar way as if I run that file as root.
So I run file /etc/rc.local and this is output:
*** Starting uWSGI 2.0.10 (64bit) on [Tue May 12 20:57:35 2015] ***
compiled with version: 4.7.2 on 14 April 2015 16:47:40
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /var/uwsgi
detected binary path: /usr/local/bin/uwsgi
setgid() to 33
setuid() to 33
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 2062113
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
Since output is shorter, I guess config files in /etc/uwsgi/vassals are not loaded and there is some problem running emperor vassals.
Anybody have any idea why?
Changing the owner of /var/www/django/ to www-data made it work.
Specifically the problem was with ownership of the file /etc/nginx/uwsgi_params.
I know that it is old question but, you got 502 Bad Gateway because you didn't tell nginx where to send requests if someone calls /. You should change location / to:
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django; # <- you miss this part
include /var/www/django/ebook/ebook/uwsgi_params;
}
and yes if you got some files permissions error you should fix it too.
Change File permissions of the sock folder...

Django app with Nginx + uWSGI on Amazon EC2

I am trying to set a Django app on Amazon EC2 using Nginx + uWSGI.
Following basic these tutorials
https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
http://www.yaconiello.com/blog/setting-aws-ec2-instance-nginx-django-uwsgi-and-mysql/#sthash.TsdnEDM8.oK2geOwb.dpbs
Nginx welcome page appears ok, Instance is running, Loadbalancer is In Service, Route53 alias to loadbalancer. But I can't see my app...
It appears that the app is running. I have tested local and it works.
I typed on terminal
uwsgi --ini myproject_uwsgi.ini
And get this
[uWSGI] getting INI configuration from myproject_uwsgi.ini
*** Starting uWSGI 1.9.15 (64bit) on [Wed Sep 11 06:14:04 2013] ***
compiled with version: 4.7.3 on 10 September 2013 09:27:00
os: Linux-3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC 2013
nodename: ip-10-252-80-160
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/myproject
writing pidfile to /tmp/myproject-master.pid
detected binary path: /usr/local/bin/uwsgi
your processes number limit is 4569
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
uwsgi socket 0 bound to UNIX address /tmp/myproject.sock fd 3
Python version: 2.7.4 (default, Apr 19 2013, 18:30:41) [GCC 4.7.3]
Set PythonHome to /home/ubuntu/.virtualenvs/myproject
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1235b30
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 363880 bytes (355 KB) for 4 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1235b30 pid: 1500 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1500)
spawned uWSGI worker 1 (pid: 1501, cores: 1)
spawned uWSGI worker 2 (pid: 1502, cores: 1)
spawned uWSGI worker 3 (pid: 1503, cores: 1)
spawned uWSGI worker 4 (pid: 1504, cores: 1)
And I try to see the error.log and I get nothing...
EDIT
myproject_uwsgi.ini
[uwsgi]
# Django-related settings
chdir = /home/ubuntu/myproject
module = myproject.wsgi
home = /home/ubuntu/.virtualenvs/myproject
env = DJANGO_SETTINGS_MODULE=myproject.settings
# process-related settings
master = true
processes = 4
socket = /tmp/myproject.sock
chmod-socket = 664
harakiri = 20
vacuum = true
max-requests = 5000
pidfile = /tmp/myproject-master.pid
daemonize = /home/ubuntu/myproject/log/myproject.log
myproject_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/myproject.sock;
# server 127.0.0.1:8001;
}
# configuration of the server
server {
listen 80;
server_name myproject.com www.myproject.com;
charset utf-8;
root /home/ubuntu/myproject/;
client_max_body_size 75M;
location /media {
alias /home/ubuntu/myproject/myproject/media;
}
location /static {
alias /home/ubuntu/myproject/myproject/static;
}
location / {
uwsgi_pass unix:///tmp/myproject.sock;
include /home/ubuntu/myproject/uwsgi_params;
}
}
`
I have finally make my app works... first I made it works with TCP, test on port 8001 but the static files was getting error 404. So I want to have at least the app working through unix sockets even with no static files...
I started changing the nginx.conf and uwsgi.ini to sockets and started receiving error 502. Much better than yesterday errors (unable to connect).
Searching and reading through web and SO... found this 502 error with nginx + uwsgi +django
Can't vote neither comment. But thanks #zzart !!
So added to my uwsgi.ini
uid = www-data
gid = www-data
chmod-socket = 777
I have added yesterday the uid (www-data), gid(www-data) and chmod-socket = 664 or 644. But not worked for me on Amazon EC2. But 777 make it works and also static files working too.
Now I will drink a beer and tomorrow will change security groups, loadbalancer and route53.
Hope it helps others.
Simple Example used FastCGI Deamon in Amazon EC2
django.sh -> https://gist.github.com/romuloigor/5707566
nginx.conf -> https://gist.github.com/romuloigor/5707527

uWSGI + nginx for django project, error with strting uwsgi

I try to up webserver for django on nginx+uwsgi, os - debian (3.1.0-1-amd64 x86_64)
nginx 1.1.8-1, uwsgi 0.9.8.3-1
configuration:
<uwsgi>
<socket>/tmp/uwsgi.sock</socket>
<process>1</process>
<master/>
<enable-threads/>
<uid>33</uid>
<gid>33</gid>
<pidfile>/tmp/uwsgi.pid</pidfile>
</uwsgi>
in file /etc/uwsgi/apps-enabled/webapp.xml
nginx configuration
location / {
uwsgi_pass unix:///tmp/uwsgi.sock;
include uwsgi_params;
uwsgi_param UWSGI_SCRIPT webapp;
uwsgi_param UWSGI_CHDIR /data/web/webapp/webapp;
}
all projet in /data/web/webapp/webapp/, here setting.py, urls ect.
in /data/web/webapp/webapp/webapp.py
import sys, os
import django.core.handlers.wsgi
sys.path.insert(0, '/data/web/webapp/webapp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()
uid and gid 33 it is www-data user
try run uwsgi as
root#uwsgi -s /var/run/uwsgi.sock -x
/etc/uwsgi/apps-enabled/webapp.xml
[uWSGI] parsing config file /etc/uwsgi/apps-enabled/webapp.xml
*** Starting uWSGI 0.9.8.3-debian (64bit) on [Wed Dec 14 21:42:02 2011] ***
compiled with version: 4.6.1 on 27 July 2011 18:25:51
writing pidfile to /tmp/uwsgi.pid
uWSGI running as root, you can use --uid/--gid/--chroot options
setgid() to 33
setuid() to 33
your memory page size is 4096 bytes
unlink(): Permission denied [socket.c line 38]
bind(): Address already in use [socket.c line 70]
how permission they want? and what's the problem..
if i run uwsgi as root error is gone, and i see
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your memory page size is 4096 bytes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi.sock fd 3
uwsgi socket 1 bound to UNIX address /tmp/uwsgi.sock fd 4
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 20732)
spawned uWSGI worker 1 (pid: 20733, cores: 1)
but when i try to access the server, ngix returns 502 error page. And more: permission error in nginx logs:
2011/12/14 21:57:17 [crit] 20739#0: *1 connect() to unix:///tmp/uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: 10.10.3.111, server: ******, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "****.****.**"
if change owner of /tmp/uwsgi.sock to nginix user in runtime (www-data), he wrote other logs
[error] 20739#0: *21 upstream prematurely closed connection while reading response header from upstream,
but still error 502 (
how solving this problem? some one can help me..
really want to use nginx+uwsgi instead of apache.
thanks
however, solution is near :)
I use tcp socket now and more, change uwsgi configuration and installed a few more packages.
was an important option --autoload.
now uwsgi has configuration like this:
<uwsgi>
<module>webapp</module>
<socket>127.0.0.1:5080</socket>
<pythonpath>/data/web/webapp/webapp</pythonpath>
<autoload/>
<daemonize>/var/log/uwsgi_webapp.log</daemonize>
<processes>1</processes>
<uid>33</uid>
<gid>33</gid>
<enable-threads/>
<master/>
<harakiri>120</harakiri>
<max-requests>5000</max-requests>
</uwsgi>
remains to solve other problem..
uwsgi use not main system python version >_<
option "pythonpath" found in plugin python26_plugin.so
*** Starting uWSGI 0.9.8.3-debian (64bit) on [Thu Dec 15 22:52:23 2011] ***
compiled with version: 4.6.1 on 27 July 2011 18:25:51
uWSGI running as root, you can use --uid/--gid/--chroot options
setgid() to 33
setuid() to 33
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
uwsgi socket 0 bound to TCP address 127.0.0.1:5080 fd 4
Python version: 2.6.7 (r267:88850, Aug 3 2011, 12:02:14) [GCC 4.6.1]
Python main interpreter initialized at 0xc47df0
threads support enabled
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
added /data/web/webapp/webapp/ to pythonpath.
WSGI application 0 (SCRIPT_NAME=) ready on interpreter 0xc47df0 pid: 22983 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 22983)
spawned uWSGI worker 1 (pid: 22984, cores: 1)
he use python 2.6.7 but main system version is 2.7.2 and all python modules installed for this, so a lot of errors in the log - repeated attempts to import non-existent, one of many typical error:
File "/usr/lib/python2.6/dist-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/lib/python2.6/dist-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/lib/python2.6/dist-packages/django/db/utils.py", line 51, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named django_mongodb_engine.base
so.. how set version of python for uwsgi?
unix sockets must obey to file permission schemes. So /var/run must be writable by www-data and nginx must be able to read/write /var/run/uwsgi.sock
If you are not familiar with this kind of things, you should use tcp sockets (choose a port and you are ready)
how set version of python for uwsgi?
Set option plugins in uwsgi settings:
[uwsgi]
...
plugins = python27
...