Internal server error django uwsgi

I am trying to follow the steps in this guide: http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html Before I even get to the nginx part I am trying to make sure that uWSGI w...

I am trying to follow the steps in this guide: http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Before I even get to the nginx part I am trying to make sure that uWSGI works correctly

my folder structure is srv/www/domain/projectdatabank/

the project databank folder contains my manage.py file

my wsgi.py file looks like this:

import os
import sys
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

do you need to see my settings.py?

i get the following error when i point myself to the browser:

-- no python application found, check your startup logs for errors ---
[pid: 10165|app: -1|req: -1/1] 66.56.35.151 () {38 vars in 681 bytes} [Tue Jul 9 18:19:46 2013] GET /admin/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 10165|app: -1|req: -1/2] 66.56.35.151 () {36 vars in 638 bytes} [Tue Jul 9 18:19:49 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)

Now when I check my uWGI log it is just the same as above.

asked Jul 9, 2013 at 18:37

tareq's user avatar

I have solved this

in my original command line did not include full path to the wsgi.py file to run uWSGI

uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file wsgi.py

to this

uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file full/path/wsgi.py

and it worked

answered Jul 9, 2013 at 18:45

tareq's user avatar

tareqtareq

1,3192 gold badges11 silver badges16 bronze badges

1

For others debugging this same error, there is another possibility: an exception is being thrown by your uwsgi.py. To test this, open a django shell in your app directly with python manage.py shell and import your uwsgi.py (use the same path as in your uwsgi.ini).

answered Aug 7, 2015 at 18:02

Fraser Harris's user avatar

9

Check out my blog post on deploying Django behind uwsgi http://blog.johannesklug.de/2012/11/27/deploying-django-behind-nginx-with-uwsgi-and-virtualenv/. I created an ini-File to setup uwsgi, which points to the app callable with the parameter module=project.wsgi:application.

The whole file reads something like this:

(env)[project@host ~]$ cat uwsgi.ini 
[uwsgi]
# path to where you put your project code
chdir=/home/project/project
 
# python path to the wsgi module, check if you have one
module=project.wsgi:application
 
# this switch tells uwsgi to spawn a master process,
# that will dynamically spawn new child processes for
# server requests
master=True
# uwsgi stores the pid of your master process here
pidfile=/home/project/master.pid
vacuum=True
# path to your virtual environment
home=/home/project/env/
# path to log file
daemonize=/home/project/log
# this is where you need to point nginx to,
# if you chose to put this in project home make
# sure the home dir is readable and executable by
# nginx
socket=/tmp/uwsgi.sock
 
### SEE UPDATE NOTICE FOR THIS ONE
env = DJANGO_SETTINGS_MODULE=project.settings

Please note that I’m using virtualenv.

You might also be missing the lines

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

in your wsgi.py

Dan Swain's user avatar

Dan Swain

2,8001 gold badge15 silver badges35 bronze badges

answered Jul 9, 2013 at 18:44

room2web's user avatar

room2webroom2web

1,1091 gold badge8 silver badges14 bronze badges

Check if u deleted any init.py file from the Djano apps. As django uses them to know which folders are apps, so they are kind of important.

answered Jul 29, 2019 at 11:31

Ibrahim Tayseer's user avatar

I got this error because my /etc/uwsgi/vassals/ ini file for the site I was running had the word «module» misspelled as «modeule». Check that file carefully if you see htis ereror.

answered May 13, 2020 at 13:55

Johnny Wales's user avatar

Johnny WalesJohnny Wales

4472 gold badges5 silver badges15 bronze badges

In uwsgi.ini

Make sure you have set the right module.

[uwsgi]
module = yourapp.wsgi:application
...

answered Aug 26, 2020 at 10:08

Lane's user avatar

LaneLane

4,4361 gold badge32 silver badges19 bronze badges

I am trying to follow the steps in this guide: http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Before I even get to the nginx part I am trying to make sure that uWSGI works correctly

my folder structure is srv/www/domain/projectdatabank/

the project databank folder contains my manage.py file

my wsgi.py file looks like this:

import os
import sys
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

do you need to see my settings.py?

i get the following error when i point myself to the browser:

-- no python application found, check your startup logs for errors ---
[pid: 10165|app: -1|req: -1/1] 66.56.35.151 () {38 vars in 681 bytes} [Tue Jul 9 18:19:46 2013] GET /admin/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 10165|app: -1|req: -1/2] 66.56.35.151 () {36 vars in 638 bytes} [Tue Jul 9 18:19:49 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)

Now when I check my uWGI log it is just the same as above.

asked Jul 9, 2013 at 18:37

tareq's user avatar

I have solved this

in my original command line did not include full path to the wsgi.py file to run uWSGI

uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file wsgi.py

to this

uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file full/path/wsgi.py

and it worked

answered Jul 9, 2013 at 18:45

tareq's user avatar

tareqtareq

1,3192 gold badges11 silver badges16 bronze badges

1

For others debugging this same error, there is another possibility: an exception is being thrown by your uwsgi.py. To test this, open a django shell in your app directly with python manage.py shell and import your uwsgi.py (use the same path as in your uwsgi.ini).

answered Aug 7, 2015 at 18:02

Fraser Harris's user avatar

9

Check out my blog post on deploying Django behind uwsgi http://blog.johannesklug.de/2012/11/27/deploying-django-behind-nginx-with-uwsgi-and-virtualenv/. I created an ini-File to setup uwsgi, which points to the app callable with the parameter module=project.wsgi:application.

The whole file reads something like this:

(env)[project@host ~]$ cat uwsgi.ini 
[uwsgi]
# path to where you put your project code
chdir=/home/project/project
 
# python path to the wsgi module, check if you have one
module=project.wsgi:application
 
# this switch tells uwsgi to spawn a master process,
# that will dynamically spawn new child processes for
# server requests
master=True
# uwsgi stores the pid of your master process here
pidfile=/home/project/master.pid
vacuum=True
# path to your virtual environment
home=/home/project/env/
# path to log file
daemonize=/home/project/log
# this is where you need to point nginx to,
# if you chose to put this in project home make
# sure the home dir is readable and executable by
# nginx
socket=/tmp/uwsgi.sock
 
### SEE UPDATE NOTICE FOR THIS ONE
env = DJANGO_SETTINGS_MODULE=project.settings

Please note that I’m using virtualenv.

You might also be missing the lines

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

in your wsgi.py

Dan Swain's user avatar

Dan Swain

2,8001 gold badge15 silver badges35 bronze badges

answered Jul 9, 2013 at 18:44

room2web's user avatar

room2webroom2web

1,1091 gold badge8 silver badges14 bronze badges

Check if u deleted any init.py file from the Djano apps. As django uses them to know which folders are apps, so they are kind of important.

answered Jul 29, 2019 at 11:31

Ibrahim Tayseer's user avatar

I got this error because my /etc/uwsgi/vassals/ ini file for the site I was running had the word «module» misspelled as «modeule». Check that file carefully if you see htis ereror.

answered May 13, 2020 at 13:55

Johnny Wales's user avatar

Johnny WalesJohnny Wales

4472 gold badges5 silver badges15 bronze badges

In uwsgi.ini

Make sure you have set the right module.

[uwsgi]
module = yourapp.wsgi:application
...

answered Aug 26, 2020 at 10:08

Lane's user avatar

LaneLane

4,4361 gold badge32 silver badges19 bronze badges

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.

Содержание

  1. Internal Server Error with Django and uWSGI 2 Emperor mode (ONLY) #650
  2. Comments
  3. Issues
  4. Context Navigation
  5. #30067 closed Bug (invalid)
  6. 500 Internal Server Error!! — Issue in wsgi in django application migrating from python2.7 to python3.6
  7. Description
  8. Внутренняя ошибка сервера с Django и uWSGI
  9. 3 ответов
  10. Установка DJango: не могу подключитья к APAche2 через WSGI

Internal Server Error with Django and uWSGI 2 Emperor mode (ONLY) #650

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:

Command being executed listed below:

Error file /tmp/uwsgi.log:

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.

The text was updated successfully, but these errors were encountered:

sorry, but the config is completely wrong, i fear you do not have a clear situation about the Emperor, vassals and standard instances. I will try to make a list, but i suggest you to start over from an official quickstart.

  • Binding the Emperor to an http address requires that address to be configured to route requests to some vassal. There are dozens of ways to do it. Basically the errors you get are from the http router in the Emperor that do not know what to do with the request.
  • mount and manage-script-name are for hosting multiple apps in the same process. It is not your case. For django, wsgi-file is more than enough
  • You are telling the Emperor to monitor the /etc/uwsgi/vassals directory 2 times (one in the ini and another in the command line, this is not an error but wastes resources)
  • with —binary-path in the Emperor you are changing the binary used by vassals (this could lead to some headache if you do not know what you are doing)
  • loading the python plugin in the Emperor makes no sense (unless special case) as the Emperor does not run code generally
  • vassals inherit the stdin,stdout and stderr of the Emperor, so if you plan to use the same log file for both, you should avoid reopening it in the vassal (it will be automatically used)

I have taken all your suggestions and cleaned the command that I was using along with editing the files to make appropriate corrections. The most important bullet, which was also the cause of most of my dismay, was what you mentioned about «binding the Emperor to an http address requires that address to be configured to route requests to some vassal.» It seems that I have misunderstood the instructions here. Listed below is the adjusted command that I execute after reading your response:

/var/www/testbed/env/bin/uwsgi —ini /etc/uwsgi/emperor.ini —http 127.0.0.1:8000

Which still doesn’t work. But the command that does work is below:

/var/www/testbed/env/bin/uwsgi —ini /etc/uwsgi/vassals/auth.ini —http 127.0.0.1:8000

What confuses me is that when I run the command directly using the ‘auth.ini’ file (listed above) everything works. The url (http://127.0.0.1:8000/testbed/auth/admin) is active and available. Though I have read many, many, parts of the the documentation over, and over, again I seem to be misinterpreting what I’m reading; leading me into an abyss-of-ignorance. This leads me to my next question. Is it possible to run uwsgi in ‘Emperor’ mode without configuring nginx? In my ignorant state I assume that what you mean by «binding the Emperor to an http address» is to use nginx (lighthttp, apache, cherokee, etc) as a proxy . Thanks for your insight thus-far.

yes you can bind an http router/proxy from the Emperor (without the need of nginx or other webservers), but you need to configure it to route requests to vassals using some rule. The Emperor is used to spawn multiple uWSGI instances, so its http router must know to which of them the request must be passed. Generally you use the domain name as the key (something like domain example.com goes to socket :4040). Here you find the options of the http router: http://uwsgi-docs.readthedocs.org/en/latest/Options.html#plugin-http. The most powerful way is the subscription system: http://uwsgi-docs.readthedocs.org/en/latest/SubscriptionServer.html

The docs refer to the fastrouter, but the options are the same just rename —fastrouter-subscription-server to http-subscription-server and your http router will start accepting subscriptions from vassals.

Finally, if you plan to host a single app, do not use the Emperor, it makes no sense.

Источник

Issues

Context Navigation

#30067 closed Bug (invalid)

500 Internal Server Error!! — Issue in wsgi in django application migrating from python2.7 to python3.6

Reported by: sindhujit ganguly Owned by: nobody
Component: Uncategorized Version: 1.11
Severity: Normal Keywords: django wsgi nginx python3
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am getting 500 Internal Server Error when I migrated my django app from python2.7 to python3.6. I have created a new virtualenv, and created all the apps individually. The virtualenv is defined in uwsgi.ini file

I have installed all the packages using pip3.6. I am not sure what I am missing. Every config in uwsgi is same as python2.7 when it was working.I am using uwsgi 2.0.13. I have restarted nginx as well. Is there a separate uwsgi for python3 which I cannot locate? The socket permissions are also same as before. Please help.

The command to start wsgi is :- /home/netadc/.venvs1/netadc/bin/uwsgi —ini /home/netadc/apps/netadc/netadc/uwsgi/netadc_uwsgi.ini —enable-threads

In wsgi logs, i see :- — no python application found, check your startup logs for errors —
[pid: 13634|app: -1|req: -1/3] x.x.x.x () <42 vars in 1029 bytes>[Mon Dec 17 09:04:40 2018] GET /netadc/home => generated 21 bytes in 0 msecs (HTTP/1.1 500)

The access logs in nginx show :- x.x.x.x — — [17/Dec/2018:09:05:43 -0700] «GET /netadc/home HTTP/1.1» 500 32

Nothing comes up in nginx error logs.

When I do manage.py shell, I see :- ImportError: bad magic number in ‘lib’: b’x03xf3rn’

I removed all the .pyc files, but then sometimes manage.py shell hangs up and sometimes it opens fine. But again after sometime, I will get the magic number error as above.

When I revert the virtualenv back to my previous virtualenv in the uwsgi.ini file which uses python2.7, I get some error logs on uwsgi.

home = /home/netadc/.venvs/netadc Log :- File «./ivpn/rest_appviewx.py», line 29

print(‘Server IP has NAT already. So no QIP update needed.’, end=’ ‘)

Источник

Внутренняя ошибка сервера с Django и uWSGI

прежде чем я даже доберусь до части nginx, я пытаюсь убедиться, что uWSGI работает правильно

моя структура папок-srv/www/domain/projectdatabank/

папка банка данных проекта содержит мой manage.py файл

мой wsgi.py файл выглядит так:

вам нужно увидеть мое settings.py?

Я получаю следующую ошибку, когда я себе в браузер:

— no python application found, check your startup logs for errors — [pid: 10165|app: -1|req: -1/1] 66.56.35.151 () <38 vars in 681 bytes>[Tue Jul 9 18:19:46 2013] GET /admin/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0) — no python application found, check your startup logs for errors — [pid: 10165|app: -1|req: -1/2] 66.56.35.151 () <36 vars in 638 bytes>[Tue Jul 9 18:19:49 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)

теперь, когда я проверяю свой журнал uWGI, он такой же, как и выше.

3 ответов

в моей исходной командной строке не был указан полный путь к wsgi.py файл для запуска uWSGI

для других, отлаживающих эту же ошибку, есть еще одна возможность: исключение создается вашим uwsgi.py . Чтобы проверить это, откройте оболочку django в своем приложении напрямую с помощью python manage.py shell и импортировать uwsgi.py (используйте тот же путь, что и в вашем uwsgi.ini ).

проверьте мой пост в блоге о развертывании Django за uwsgi http://blog.johannesklug.de/2012/11/27/deploying-django-behind-nginx-with-uwsgi-and-virtualenv/ — . Я создал ini-файл для настройки uwsgi, который указывает на приложение, вызываемое с параметром module=project.wsgi:application .

весь файл читает что-то вроде этого:

обратите внимание, что я использую virtualenv.

Источник

Установка DJango: не могу подключитья к APAche2 через WSGI

Решил попробовать установить Django на пощупать.

Нарыл книжку «Django. Разработка веб-приложений на Python», почитал интернет-ресурсы. Стал устанавливать. Система Debian.

Установил пакеты с Апачем2, Питоном, базовый Django. Подключение к апачу делаю, согласно рекомендациям, через WSGI. Мне необходимо установить проект в директорию /app виртуального хоста local_libretag.ru.

Последовательность моих действий:

1. Сделал директорию /var/www/libretag

2. Выполнил в этой директории команду:

В результате в каталоге /var/www/libretag появилось следующее дерево:

3. В каталог /var/www/libretag/app поместил файл django.wsgi следующего содержания:

4. Настроил виртуальных хост local_libretag.ru.

Содержимое файла /etc/apache2/sites-enabled/local_libretag.ru.conf:

Вот, в принципе и все. Перезагрузил апач2, открываю урл:

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Полез в логи апача. В файле /var/log/apache2/error.log обнаружились записи:

То есть, Питон по WSGI подключился и вызывается. Django установлен и вроде как работает. Но тиолько не так как надо.

В файле /var/www/linuxtrash/app/app/settings.py есть строка:

Я пробовал ее заменять на:

— толку никакого, все те же ошибки и в окне браузера и в логе.

Вопрос. Как все-таки настроить Django? Как избавиться от вышеприведенной ошибки?

Источник

I’m trying to host an app using Nginx on Linode.com but I’m stuck early on uWSGI config.

I’ve used «Getting Started» guide and «WSGI using uWSGI and nginx on Ubuntu 12.04 (Precise Pangolin)» guide and I’ve succesfully deployed Nginx (got Nginx welcome message in browser).

Although above tutorial is for Ubuntu 12.04 I’ve used 14.04.

The problem starts when I got to uWSGI configuration and ‘Hello World’ Python app. Going to location / in browser returns Failed to load resource: the server responded with a status of 500 (Internal Server Error) and nothing gets logged in server error.log. location /static works though and serves files without a hitch.

I’ve tried many things and looked extensively for fix on Google and Stackoverflow but nothing, and I’m kind of frustrated right now.

Thank you for any help.

Here are my config files (I’ve hidden my domain and ip):

/etc/hosts

127.0.0.1   localhost
127.0.1.1   ubuntu
XX.XX.XX.XXX mars

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

/etc/nginx/sites-enabled/example.com

server {
    listen      80;
    server_name $hostname;
    access_log  /srv/www/example.com/logs/access.log;
    error_log   /srv/www/example.com/logs/error.log;

    location / {
        #uwsgi_pass 127.0.0.1:9001;
        uwsgi_pass  unix:///run/uwsgi/app/example.com/example.com.socket;
        include     uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
    }

    location /static {
        root        /srv/www/example.com/public_html/;
        index       index.html index.htm;
    }

}

/etc/uwsgi/apps-enabled/example.com.xml

<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/example.com/example.com.socket</socket>
    <pythonpath>/srv/www/example.com/application/</pythonpath>
    <app mountpoint="/">

        <script>wsgi_configuration_module</script>

    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>

/srv/www/example.com/application/wsgi_configuration_module.py

import os
import sys
sys.path.append('/srv/www/example.com/application')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg'

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    return 'Hello world!'

last access log

XX.XX.XX.XXX - - [05/Jul/2015:10:03:37 -0400] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
XX.XX.XX.XXX - - [05/Jul/2015:10:03:38 -0400] "GET /favicon.ico HTTP/1.1" 500 32 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"

only error log I've got only one time when trying to fix this

2015/07/05 08:49:06 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com"
2015/07/05 08:49:07 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com", referrer: "http://example.com/"

Я пытаюсь выполнить шаги в этом руководстве:http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

прежде чем я даже доберусь до части nginx, я пытаюсь убедиться, что uWSGI работает правильно

моя структура папок-srv/www/domain/projectdatabank/

папка банка данных проекта содержит мой manage.py файл

мой wsgi.py файл выглядит так:

import os
import sys
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

вам нужно увидеть мое settings.py?

Я получаю следующую ошибку, когда я себе в браузер:

-- no python application found, check your startup logs for errors ---
[pid: 10165|app: -1|req: -1/1] 66.56.35.151 () {38 vars in 681 bytes} [Tue Jul 9 18:19:46 2013] GET /admin/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---
[pid: 10165|app: -1|req: -1/2] 66.56.35.151 () {36 vars in 638 bytes} [Tue Jul 9 18:19:49 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)

теперь, когда я проверяю свой журнал uWGI, он такой же, как и выше.

3 ответов


Я решил эту

в моей исходной командной строке не был указан полный путь к wsgi.py файл для запуска uWSGI

uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file wsgi.py

этой

uwsgi --http :8000 --chdir /srv/www/databankinfo.com/projectdatabank/ --wsgi-file full/path/wsgi.py

и он работал


для других, отлаживающих эту же ошибку, есть еще одна возможность: исключение создается вашим uwsgi.py. Чтобы проверить это, откройте оболочку django в своем приложении напрямую с помощью python manage.py shell и импортировать uwsgi.py (используйте тот же путь, что и в вашем uwsgi.ini).


проверьте мой пост в блоге о развертывании Django за uwsgi http://blog.johannesklug.de/2012/11/27/deploying-django-behind-nginx-with-uwsgi-and-virtualenv/ — … Я создал ini-файл для настройки uwsgi, который указывает на приложение, вызываемое с параметром module=project.wsgi:application.

весь файл читает что-то вроде этого:

(env)[project@host ~]$ cat uwsgi.ini 
[uwsgi]
# path to where you put your project code
chdir=/home/project/project

# python path to the wsgi module, check if you have one
module=project.wsgi:application

# this switch tells uwsgi to spawn a master process,
# that will dynamically spawn new child processes for
# server requests
master=True
# uwsgi stores the pid of your master process here
pidfile=/home/project/master.pid
vacuum=True
# path to your virtual environment
home=/home/project/env/
# path to log file
daemonize=/home/project/log
# this is where you need to point nginx to,
# if you chose to put this in project home make
# sure the home dir is readable and executable by
# nginx
socket=/tmp/uwsgi.sock

### SEE UPDATE NOTICE FOR THIS ONE
env = DJANGO_SETTINGS_MODULE=project.settings

обратите внимание, что я использую virtualenv.

вы также можете пропустить строки

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

в вашей wsgi.py


Запуская связку nginx и uwsgi для запуска django проекта, столкнулся с ошибкой 500 на стороне nginx. Я залез в /var/log/nginx/error.log и нашел там конкретное название ошибки:

worker_connections are not enough while connecting to upstream ...

Я пробовал увеличить worker_connections в /etc/nginx/nginx.conf, но при большом значении вылазить ошибка:

socket() failed (24: To many open files)

Пробовал решить это с помощью создания в том же /etc/nginx/nginx.conf параметра — worker_limit_nofile, но это возвращает ошибку worker_connections are not enough while connecting to upstream. Дальнейшая игра с увеличением, уменьшением этих двух параметров (worker_connections и worker_limit_nofile) ничего не дает. Мне лишь выкидывает то первую ошибку, то вторую.

В общем, пожалуйста, помогите избавиться от ошибок. Благодарю заранее! (прилагаю конфиги)

  GNU nano 4.8                 /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
#bilo auto
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
worker_rlimit_nofile 10000;
events {
        worker_connections 20000;
        # 768 bilo tyt
        # multi_accept on;
}
...

  GNU nano 4.8           /etc/uwsgi/apps-enabled/myapp.ini
[uwsgi]
chdir = /root/eva/lawyer
env = DJANGO_SETTINGS_MODULE= lawyer.settings.production
wsgi-file = lawyer/wsgi.py
#module = lawyer.uwsgi:application
workers = 1
max-requests = 5000
#plugins-dir=/usr/lib/uwsgi/plugins/
#plugins = python3
#virtualenv = /root/eva/venv
home = /root/eva/venv
processes = 5
threads = 2
master = true
die-on-term = true
socket = /run/sedova.sock
chmod-socket = 666
vacuum = true
uid = www-data
gui = www-data

GNU nano 4.8 /etc/nginx/conf.d/my_app.conf

server {
        listen 82;
        server_tokens off;
        server_name 185.46.8.164;
    
        #root /var/www/
        location / {
            include uwsgi_params;
            uwsgi_pass unix:///run/uwsgi/app/myapp/socket;
            #
            try_files $uri $uri/ =404;
            #
            proxy_pass http://185.46.8.164:82;
            proxy_set_header X-Forwarded-Host $server_name;
            proxy_set_header X-Real-IP $remote_addr;
            add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
            add_header Access-Control-Allow-Origin *;
        }...

VPS server on Linux (ubuntu 20.04)
nginx version: nginx/1.18.0 (Ubuntu)
uwsgi 2.0.20
python3
django 3.2.8

Вернуться на верх

Понравилась статья? Поделить с друзьями:
  • Invalid extended processor state windows 10 как исправить
  • Invalid email for inbound fax freepbx 13 как исправить
  • Invalid drive specification dos как исправить
  • Invalid drive geometry как исправить victoria
  • Invalid drive e hamachi как исправить