I'm having problems when I'm trying to deploy my Django application using nginx and uwsgi . I will start by putting here the config files:
tutorial_nginx.conf
upstream django {
server unix:///home/mrgrj/site/blog/tutorial.sock;
}
server {
listen 8000;
server_name xx.xx.xxx.xx;
location /media {
alias /home/mrgrj/site/blog/polls/templates;
}
location /static/ {
root /home/mrgrj/site/blog/polls/templates/polls;
}
location / {
uwsgi_pass django;
include /home/mrgrj/site/blog/uwsgi_params;
}
}
tutorial_uwsgi.ini
[uwsgi]
chdir = /home/mrgrj/site/blog
module = wusgi.py
home = /home/mrgrj/site
master = true
processes = 10
socket = /home/mrgrj/site/blog/tutorial.sock
vacuum = true
I followed this tutorial from Official Django Documentation and unfortunately I didn't succeed to finish it as I encountered some issues.
The nginx server is set up correctly as it displays me the right page when I access the ip from the web browser. The django application is working when I am running python manage.py runserver 0.0.0.0:8000. The issues that I have, regarding that tutorial:
uwsgi --http :8000 --module mysite.wsgi . I don't have such a file, but I have something simillar which is called wsgy.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings")
application = get_wsgi_application()
When I am trying tu run that command using wsgi.py it says Internal server error on my browser ( I am accessing it via ip:8000 ). Traceback:
* Starting uWSGI 2.0.10 (64bit) on [Sun Apr 12 16:42:15 2015] compiled with version: 4.8.2 on 10 April 2015 08:25:41 os:
Linux-3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014
nodename: alex-test machine: x86_64 clock source: unix detected number
of CPU cores: 1 current working directory: /home/mrgrj/site/blog/blog
detected binary path: /usr/local/bin/uwsgi !!! no internal routing
support, rebuild with pcre support !!!
WARNING: you are running uWSGI without its master process manager your processes number limit is 3750 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread
robust mutexes thunder lock: disabled (you can enable it with
--thunder-lock) uWSGI http bound on :8000 fd 4 spawned uWSGI http 1 (pid: 2169) uwsgi socket 0 bound to TCP address 127.0.0.1:41225 (port
auto-assigned) fd 3 Python version: 2.7.6 (default, Mar 22 2014,
23:03:41) [GCC 4.8.2]
Python threads support is disabled. You can enable it with --enable-threads Python main interpreter initialized at 0x122d0c0 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 Traceback (most recent call last): File "./wsgi.py", line 16, in
application = get_wsgi_application() File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14,
in get_wsgi_application
django.setup() File "/usr/local/lib/python2.7/dist-packages/django/init.py", line 17,
in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) File "/usr/local/lib/python2.7/dist-packages/django/conf/init.py",
line 48, in getattr
self._setup(name) File "/usr/local/lib/python2.7/dist-packages/django/conf/init.py", line
44, in _setup
self._wrapped = Settings(settings_module) File "/usr/local/lib/python2.7/dist-packages/django/conf/init.py", line
92, in init
mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name) ImportError: No module named blog.settings 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: 2168, cores: 1)
Another problem that I have is when I am trying to run uwsgi --socket :8001 --wsgi-file test.py. It gives me a **no data received message** `(Unable to load the webpage because the server sent no data.)'
Can anybody help me out, please ?
Related
I am trying to run one sample application with uWSGI file directive using two files for it testService.ini(config file) & testService.py (application file).
**testService.ini**
[uwsgi]
wsgi-file = '/opt/testService/testService.py'
callable = app
**testService.py**
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
running the above file using : uwsgi --http :9090 --wsgi-file testService.ini
Output:
Starting uWSGI 2.0.17 (64bit) on [Thu Jun 21 15:52:33 2018]
compiled with version: 5.4.0 20160609 on 14 June 2018 10:09:32
os: Linux-4.13.0-45-generic #50~16.04.1-Ubuntu SMP Wed May 30 11:18:27 UTC 2018
nodename: ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 8
current working directory: /opt/testService
detected binary path: /home/jmallick/.local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 15481
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 :9090 fd 4
spawned uWSGI http 1 (pid: 7848)
uwsgi socket 0 bound to TCP address 127.0.0.1:45781 (port auto-assigned) fd 3
Python version: 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
Python threads support is disabled. You can enable it with --enable-threads
Python main interpreter initialized at 0x824400
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
Operational MODE: single process
File "testService.ini", line 2
**wsgi-file = '/opt/testService/testService.py'
SyntaxError: can't assign to operator
failed to compile python file testService.ini**
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: 7847, cores: 1)
And over the browser I am getting "Internal Server Error". Can someone help me understanding what I am doing wrong here ?
I'm trying to setup uwsgi (and nginx eventually), but right now am stuck on uwsgi. I'm getting the following error when I try to run the server normally:
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
And this is the output from running command uwsgi --http :8000 --module Hellfish.wsgi:
*** Starting uWSGI 2.0.17 (64bit) on [Tue Jul 3 18:34:40 2018] ***
compiled with version: 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) on 03 July 2018 20:44:01
os: Darwin-16.7.0 Darwin Kernel Version 16.7.0: Fri Apr 27 17:59:46 PDT 2018; root:xnu-3789.73.13~1/RELEASE_X86_64
nodename: Whodinis-MacBook-Pro.local
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /Users/whodini/Desktop/who/Web/Hellfish
detected binary path: /Users/whodini/Desktop/who/Web/Hellfish/env/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 709
your memory page size is 4096 bytes
detected max file descriptor number: 256
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 5
spawned uWSGI http 1 (pid: 70999)
uwsgi socket 0 bound to TCP address 127.0.0.1:59020 (port auto-assigned) fd 4
Python version: 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x7fd92082c800
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72888 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
base dir path
Traceback (most recent call last):
File "./Hellfish/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'django_countries'
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: 70998, cores: 1)
Not sure why it can't import module Django_countries. I'm kind of operating blind here because this is the first time I've done this and having trouble following docs and tutorials. I've tried to kill the port and restart it but came up with this issue again. Also not sure if my .ini file is in the right place or if its configured correctly. I put it in the same directory as my Hellfish.wsgi file. Hellfish is the name of my project. Finally, here is the contents of my .ini file:
[uwsgi]
socket = 127.0.0.1:8000
chdir = /Users/whodini/Desktop/who/Web/Hellfish/
home = /Users/whodini/Desktop/who/Web/Hellfish/env
module = Hellfish.wsgi:application
wsgi-file = Hellfish/wsgi.py
master = true
pidfile=/tmp/project-master.pid
vacuum=True
max-requests=5000
processes = 4
threads = 2
stats = 127.0.0.1:8000
Some help here would be much appreciated.
When I use uwsgi to connect the
$ uwsgi --http :8000 --plugin python --module myProject.wsgi
I get the bellow error:
!!! UNABLE to load uWSGI plugin: dlopen(./python_plugin.so, 10): image not found !!!
There are whole traceback:
(venv) MacBook-Pro:myProject ldl$ uwsgi --http :8000 --plugin python --module myProject.wsgi
!!! UNABLE to load uWSGI plugin: dlopen(./python_plugin.so, 10): image not found !!!
*** Starting uWSGI 2.0.17 (64bit) on [Wed May 9 11:24:54 2018] ***
compiled with version: 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2) on 09 May 2018 02:32:54
os: Darwin-16.7.0 Darwin Kernel Version 16.7.0: Mon Nov 13 21:56:25 PST 2017; root:xnu-3789.72.11~1/RELEASE_X86_64
nodename: MacBook-Pro.local
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /Users/sss/Desktop/QIYUN/Project/myProject
detected binary path: /Users/sss/Desktop/myProject/Project/myProject/venv/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 709
your memory page size is 4096 bytes
detected max file descriptor number: 10240
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 5266)
uwsgi socket 0 bound to TCP address 127.0.0.1:54904 (port auto-assigned) fd 3
Python version: 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x7f82d9e00590
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72888 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./myProject/wsgi.py", line 18, in <module>
from 管理员后台.网站管理admin_website_chat.views import sio
File "./管理员后台/网站管理/admin_website_chat/views.py", line 2, in <module>
from 管理员后台.用户管理.admin_usermanage.models import User
File "./管理员后台/用户管理/admin_usermanage/models.py", line 6, in <module>
from django.contrib.auth.models import AbstractUser
File "/Users/sss/Desktop/QIYUN/Project/myProject/venv/lib/python3.5/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/sss/Desktop/myProject/Project/myProject/venv/lib/python3.5/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Users/sss/Desktop/myProject/Project/myProject/venv/lib/python3.5/site-packages/django/db/models/base.py", line 110, in __new__
app_config = apps.get_containing_app_config(module)
File "/Users/sss/Desktop/myProject/Project/myProject/venv/lib/python3.5/site-packages/django/apps/registry.py", line 247, in get_containing_app_config
self.check_apps_ready()
File "/Users/sss/Desktop/myProject/Project/myProject/venv/lib/python3.5/site-packages/django/apps/registry.py", line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
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: 5265, cores: 1)
My computer is Macbook Pro 2015.
remove the option --plugin python and the error should go away.
Following a bunch of tutorials, I wrote my first django app and then decided to deploy it on a linode server. Following their tutorial, I only got so far. The best I could tell, that was based on an earlier version of Ubunto and I tried some other things, including the uwsgi quickstart tutorial.
I got far enough that the command 'python manage.py runserver' would serve up my site and wanted to move on to using uwsgi to do the same.
It seems as though there is some environment variable missing. When I try to start uwsgi from the command line with:
uwsgi --http :8000 --module dynamicefl.wsgi
I get the following:
*** Starting uWSGI 2.0.15 (64bit) on [Fri Aug 11 19:37:04 2017] ***
compiled with version: 6.3.0 20170406 on 10 August 2017 23:41:13
os: Linux-4.9.36-x86_64-linode85 #1 SMP Thu Jul 6 15:31:23 UTC 2017
nodename: roosevelt
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/django/worksheets/dynamic-efl
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3941
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 5998)
uwsgi socket 0 bound to TCP address 127.0.0.1:43637 (port auto-assigned) fd 3
Python version: 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x562bdad6fda0
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 ***
Traceback (most recent call last):
File "./dynamicefl/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.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: 5997, cores: 1)
A lot of the tutorials emphasize putting the path to the virtual environment in the .ini file, and I did (double checking with 'env' that I had the virtual environment right.) Here is the .ini file I'm working with
[uwsgi]
home = /home/django/Env/worksheets
chdir = /home/django/worksheets/dynamic-efl/dynamicefl
module = dynamicefl.wsgi::application
uid = www-data
gid = www-data
socket = localhost:9191
chmod-socket = 644
chown-socket = www-data
processes = 4
threads = 2
logto = /var/log/uwsgi.log
I have experimented with changing the chdir command some, as I'm not sure exactly where it should be pointing, but regarless of where it points that results in a similar line in uwsgi.log:
-- no python application found, check your startup logs for errors ---
(Fun fact: I haven't been able to find reference to uwsgi startup logs)
If I go to the site in my web browser, I get an 'Internal Server Error' message.
I don't think that anything is getting as far an nginx, but I can include the .conf file and error logs, too, if that's helpful.
I know that there are a log of similar questions, but I've looked at them and they're not helping me. (Which is not to say that they don't contain the answer.)
The django docs helped me out here. It turns out that my reference to the module was apparently wrong. I had a colon too many in the reference to the module. The corrected .ini reads:
module = dynamicefl.wsgi:application
What helped was resolving to battle it out until I could serve the site purely from uwsgi, so that I could stop restarting services.
I'm trying to run a Flask application using a ubuntu 12.04 server with nginx and uWSGI however after starting the server, specifying the wsgi.ini file and then starting nginx, I try to access the page but I get a 502 bad gateway error with nginx. I know that it is an issue with the flask application and uWSGI. I checked the uWSGI logs and found this:
*** Starting uWSGI 2.0.11.1 (64bit) on [Thu Sep 17 19:38:03 2015] ***
compiled with version: 4.8.4 on 17 September 2015 15:58:04
os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
nodename: ip-172-31-30-153
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/myapp
writing pidfile to /home/ubuntu/myapp/myapp.pid
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) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7862
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:5000 fd 3
Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2]
Set PythonHome to /home/ubuntu/myapp
ImportError: No module named site
I found this question's top answer but saw received the same error. If it is something to do with PYTHONHOME, I'm following this guide and it states:
The $PYTHONPATH variable seems to get unset randomly, and causes
errors for later steps. To avoid this, add the following line to the
top of your ~/.bashrc file:
export
PYTHONPATH='/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages/PILcompat'
So what could be the issue? Is it PYTHONHOME or another factor affecting it? Thanks.
Edit:
My uwsgi.ini:
[uwsgi]
home = /home/ubuntu/myapp
wsgi-file = %(home)/run.py
socket = 127.0.0.1:5000
callable = app
module = app
pythonpath = %(home)
daemonize = %(home)/myapp.log
pidfile = %(home)/myapp.pid
To run it, I use uwsgi uwsgi.ini.