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)
Related
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 complete the upgrade of my Django project from 1.4 to 1.8. I've got my site running locally without any issues. However when I deploy the upgraded code I get a 502 bad gateway. The site was running on the server using Django 1.4 without any issues.
The 1.4 version of the code was using Gunicorn with Supervisor. I couldn't get the upgraded code to run with Gunicorn so I tried using uWsgi, which resulted in me having the same issue.
I have other sites using Django 1.4 on this same server with are working fine.
I cant really see any useful errors in any logs, the only error I see is in the Nginx log:
2016/02/24 10:32:16 [error] 15475#0: *52 upstream prematurely closed connection while reading response header from upstream, client: [IP address], server: myapp.*, request: "GET /api/get_campaign/ HTTP/1.1", upstream: "http://unix:///var/run/supervised-sockets/myapp-uwsgi.sock:/api/get_campaign/", host: "[site-name]"
Nginx config:
upstream django {
server unix:///var/run/supervised-sockets/myapp-uwsgi.sock;
}
server {
listen 80;
server_name myapp.*;
access_log /var/log/nginx/myapp_access.log;
error_log /var/log/nginx/myapp_error.log notice;
# rewrite URLs of the form static/.*/*.gz to non .gz then gzip_static module will check
# for the compressed version on disk. Round about method to get around django-compressor
# adding the .gz extension
rewrite /static/(.*)\.(css|js)\.gz$ /static/$1.$2 last;
rewrite /media/(.*)\.(css|js)\.gz$ /media/$1.$2 last;
location /static/CACHE/ {
root /srv/myapp/releases/current/myapp/myapp/assets/;
expires max;
break;
}
location /favicon.ico {
root /srv/myapp/releases/current/myapp/myapp/assets/static/img/;
}
location /static/ {
root /srv/myapp/releases/current/myapp/myapp/assets/;
}
location /media/ {
root /srv/myapp/shared/;
}
location / {
uwsgi_pass django;
include /srv/myapp/releases/current/myapp/uwsgi_params;
proxy_set_header HOST $http_host;
#proxy_pass http://unix:/var/run/supervised-sockets/myapp-uwsgi.sock;
proxy_pass http://myapp;
proxy_buffering off; # no need as services are local
proxy_connect_timeout 3000s;
proxy_read_timeout 3000s;
}
This is my uWsgi ini file:
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /srv/myapp/releases/current/myapp
# Django's wsgi file
module = myapp_wsgi:application
# the virtualenv (full path)
home = /srv/myapp/
#virtualenv = myapp
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 2
# the socket (use the full path to be safe
socket = /var/run/supervised-sockets/myapp-uwsgi.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
chown-socket = myapp
# clear environment on exit
vacuum = true
buffer-size=32768
#die-on-term = true
#wsgi-file = myapp/myapp_wsgi.py
When I run uWsgi this is the output:
[uWSGI] getting INI configuration from myapp_uwsgi.ini
*** Starting uWSGI 2.0.12 (64bit) on [Wed Feb 24 10:45:16 2016] ***
compiled with version: 4.6.3 on 22 February 2016 17:10:22
os: Linux-3.2.0-77-virtual #114-Ubuntu SMP Tue Mar 10 17:38:02 UTC 2015
nodename: ip-10-0-9-42
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /srv/myapp/releases/1d4cad9dae00479763636fab34ab2224a59449c4/myapp
detected binary path: /srv/myapp/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /srv/myapp/releases/current/myapp
your processes number limit is 59476
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/run/supervised-sockets/myapp-uwsgi.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 2.7.3 (default, Dec 18 2014, 19:25:50) [GCC 4.6.3]
Set PythonHome to /srv/myapp/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xf5b420
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 304320 bytes (297 KB) for 2 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xf5b420 pid: 30534 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 30534)
spawned uWSGI worker 1 (pid: 30541, cores: 1)
spawned uWSGI worker 2 (pid: 30542, cores: 1)
This is the Gunicorn config that Supervisor uses:
[program:myapp-gunicorn]
command=/srv/myapp/bin/gunicorn -b unix:/var/run/supervised-sockets/myapp-gunicorn.sock -w 2 myapp_wsgi:application -t 30 --max-requests 600 --timeout 300
numprocs=1
numprocs_start=0
priority=896
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=60
directory=/srv/myapp/releases/current/myapp
user=myapp
redirect_stderr=false
stdout_logfile=/var/log/supervisor/myapp/myapp-gunicorn.out
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
stderr_logfile=/var/log/supervisor/myapp/myapp-gunicorn.err
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=5
This is my Django wsgi file:
import os
import sys
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(THIS_DIR, "/"))
sys.path.insert(0, os.path.join(THIS_DIR, "myapp/apps"))
sys.path.insert(0, os.path.join(THIS_DIR, "myapp/lib"))
os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Any help is really appreciated as I've been looking into this for a while.
Thanks
I'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 ?
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)
I use supervisord for managing tornado with no issuse wnhile using nginx as a load balancer.
I am having severe issues with supervisor and uWSGI with nginx as a load blancer. I am using bottle as the framework.
when I run the below from the command line and I load a page in FF hitting nginx, all works great.
sudo command = /usr/local/bin/uwsgi --loop gevent --socket 127.0.0.1:8070 --wsgi-file /home/ubuntu/workspace/uwsgiServer.py -b 32768 --master --async 5 --enable-threads --listen 100 --uid root
If I place the command line in supervior then I get page not found.
uWSGI Error
Python application not found
[program:uwsgi]
#autostart=true
#autorestart=true
#process_name = uwsgi-%(process_num)s
command = /usr/local/bin/uwsgi --loop gevent --socket 127.0.0.1:8070 --wsgi-file /home/ubuntu/workspace//uwsgiServer.py -b 32768 --master --async 5 --enable-threads --listen 100 --uid root
#--port=%(process_num)s
#--log_file_prefix=%(here)s/logs/%(program_name)s-%(process_num)s.log
#numprocs = 1
#numprocs_start = 8070
Here are the relevant portions of the nginx.conf file:
upstream uwsgi_b {
server 127.0.0.1:8070;
}
location /u/ {
include uwsgi_params;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param Host $http_host;
uwsgi_pass uwsgi_b;
}
You might probably add some more params to supervisord config, like --pp (python path) to the uwsgi command, and maybe some environment variables:
[program:uwsgi]
command = /usr/local/bin/uwsgi
--loop gevent
--socket 127.0.0.1:8070
--wsgi-file uwsgiServer.py
--buffer-size 32768 --master --async 5 --enable-threads --listen 100 --uid root
--pp /home/ubuntu/workspace/
autostart=true
autorestart=true
environment=ENV_VAR='var'
user=root # or other
group=root # or other
directory=/home/ubuntu/workspace/
umask=022
EDIT: Removed Django-specific settings