uwsgi no app loaded. going in full dynamic mode ubuntu

部署运行你感兴趣的模型镜像

 http://jawher.me/2012/03/16/multiple-python-apps-with-nginx-uwsgi-emperor-upstart/


==============================================================

ERROR --> uwsgi  no app loaded. going in full dynamic mode

1、安装

uwsgi-plugin-python 插件

2、xml中加入

<plugins>python</plugins>

==============================================================

This is a recipe on how to easily run multiple Python web applications using uwsgi server (in emperor mode) and behind nginx.Most existing docs and blogs would show how to manually start uwsgi to run a single app. In this post, I'll show how to configure uwsgi as a system service (with upstart) capable of serving multiple python WSGI compliant web applications by simply placing them in a standard location and adding an standard xml file.

It took me many many hours and sleepless nights to get this setup to work. I was on the verge of giving up on uwsgi/nginx and falling back to apache/mod python. I'm not proud of it, but when it worked, I had (and still don't have) no idea why it did. So I would advice the readers not to change too much at a time, and rather work incrementally, with small changes at a time and immediate testing afterwards.

I'm using this setup on a couple EC2 machines running Ubuntu 11.10, nginx 1.0.5-1, Python 2.7.2, uwsgi 0.9.8.1-1 and using the bottle web framework, but the sameshould work for any other WSGI compliant framework.

1. Installing the required software

  • We'll (of course) need Python. It comes pre-installed on Ubuntu and other linuxes. Nothing to do here.
  • uwsgi: sudo aptitude install uwsgi uwsgi-plugin-python
  • bottle (optional): Since I'll be using Bottle framework for the test applications, we'll need to have it installed for this recipe to work, but if you're using another framework, you could skip this step. Just run this command:sudo easy_install bottle. If easy_install isn't already installed, runsudo aptitude install python-setuptools.
  • nginx: sudo aptitude install nginx-full

2. Configuration

uwsgi

We'll run uwsgi using upstart so that it is automatically started on startup.

We'll create a uwsgi.conf file in /etc/init:

sudo emacs /etc/init/uwsgi.conf:

With this content:

# uWSGI - manage uWSGI application server                                                                                                                                                                
#                                                                                                                                                                                                    

description     "uWSGI Emperor"

start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]

respawn

env LOGTO=/var/log/uwsgi.log
env BINPATH=/usr/bin/uwsgi

exec $BINPATH --emperor /home/ubuntu/apps/vassals/ --logto $LOGTO

Notice the path telling uwsgi emperor mode where to look for applications' configuration files (We'll be using the xml syntax here).You'll need to modify this to match your setup.

Then run this command to refresh the services configuration:

sudo initctl reload-configuration

We also want to make sure that uwsgi is using the system installed python (2.7 in this case) and not another version (2.6), so we need to run this:

sudo update-alternatives --set uwsgi /usr/bin/uwsgi_python27

And start the uwsgi service:

sudo service uwsgi start

nginx

We'll create a apps.conf file in the /etc/nginx/sites-enabled directory to tell nginx to pass through requests to uwsgi:

sudo emacs /etc/nginx/sites-enabled/apps.conf

server {
  listen 80;
  server_name jawher.me;
  index index.html;

  location /app1/ {
    include uwsgi_params;
    uwsgi_param SCRIPT_NAME /app1;
    uwsgi_modifier1 30;
    uwsgi_pass unix://tmp/app1.sock;
  }

  location /app2/ {
    include uwsgi_params;
    uwsgi_param SCRIPT_NAME /app2;
    uwsgi_modifier1 30;
    uwsgi_pass unix://tmp/app2.sock;
  }
}

You'll need to customize this file to match your setup (server name, apps locations, socket names, etc.)

Also, there's a bit of magic here, the uwsgi_param SCRIPT_NAME /app? anduwsgi_modifier1 30 thingies. Without them, requestingjawher.me/app1/index would end up callingapp1/index on the bottle web application (i.e. the nginx location gets passed to the wsgi application, which is not what we want most of the time). With this modifier and script param thingies, the nginx location is stripped before invoking the python application.

Start the nginx server if it is not already running:

sudo service nginx start

Also, whenever you change the nginx config files, remember to run the following command:

sudo service nginx reload

3. The test applications

We'll create to test web applications to test our setup:

An app in this case is a python file that defines a bottle app:

emacs /home/ubuntu/apps/app1/app1.py

import bottle
import os

@bottle.get('/index')
def index():
    return "App 1 live and kicking"

if __name__ == '__main__':
    bottle.debug(True)
    bottle.run(reloader=True, port=8080)
else:
    os.chdir(os.path.dirname(__file__))
    application = bottle.default_app()

This file can be executed with python, in which case the main bloc will launch the application in debug mode, or with uwsgi without a change to the file. Don't change the variable nameapplication, as that's what uwsgi will be looking for (unless you tell it otherwise).

We'll also need an xml file to tell uwsgi emperor mode how to handle our app:

emacs /home/ubuntu/apps/vassals/app1.xml

<uwsgi>
    <plugins>python</plugins>
    <master>true</master>
    <processes>1</processes>
    <vaccum>true</vaccum>
    <chmod-socket>666</chmod-socket>
    <socket>/tmp/%n.sock</socket>
    <uid>www-data</uid>
    <gid>www-data</gid>
    <pythonpath>%d../%n</pythonpath>
    <module>%n</module>
</uwsgi>

This config file is completely generic, and we could reuse the exact same content for any other app. In order to do this, it has to heavily rely on these conventions:

  • the xml config file has to have the same name as the python module that exports the wsgi application (app1.xml andapp1.py)
  • the python module file name has to match its directory name (app1.py in anapp1 dir)

If this is not acceptable for your setup, you'll need to change the values of the<pythonpath> and<module> tags to match your setup.

The second application is exactly the same, except for 'app 1' which gets replaced by 'app 2':

emacs /home/ubuntu/apps/app2/app2.py

import bottle
import os

@bottle.get('/index')
def index():
    return "App 2 live and kicking"

if __name__ == '__main__':
    bottle.debug(True)
    bottle.run(reloader=True, port=8080)
else:
    os.chdir(os.path.dirname(__file__))
    application = bottle.default_app()

emacs /home/ubuntu/apps/vassals/app2.xml

<uwsgi>
    <plugins>python</plugins>
    <master>true</master>
    <processes>1</processes>
    <vaccum>true</vaccum>
    <chmod-socket>666</chmod-socket>
    <socket>/tmp/%n.sock</socket>
    <uid>www-data</uid>
    <gid>www-data</gid>
    <pythonpath>%d../%n</pythonpath>
    <module>%n</module>
</uwsgi>

4. Troubleshooting

When it doesn't work, you'll usually end up with an unhelpful 502 error. To diagnose the problem:

  • Check that the sockets were created: ls /tmp and that nginx's process can read, write and execute them. This shouldn't happen though as we specifiedchmod 666 in the applications config file.
  • Check that the apps were correctly loaded in /var/log/uwsgi.log: if you find this message\*\*\* no app loaded. going in full dynamic mode \*\*\*, then go back and double check the module name and path in the app xml file, or try to run the app with python, as inpython app1.py to see if there aren't any missing imports or other errors. You may also run into this if the user under which uwsgi is running doesn't have read permissions on the app python files.
  • Make sure that your app runs with the same version of python that uwsgi uses. Usually, you'll just want to configure uwsgi to use the system-wide python install.
  • /var/log/nginx/error.log might turn out some useful info too.

您可能感兴趣的与本文相关的镜像

EmotiVoice

EmotiVoice

AI应用

EmotiVoice是由网易有道AI算法团队开源的一块国产TTS语音合成引擎,支持中英文双语,包含2000多种不同的音色,以及特色的情感合成功能,支持合成包含快乐、兴奋、悲伤、愤怒等广泛情感的语音。

03-16
[uWSGI] getting INI configuration from /home/zzc/web_Django/myproject/uwsgi.ini *** Starting uWSGI 2.0.30 (64bit) on [Wed Aug 13 14:19:41 2025] *** compiled with version: 11.4.0 on 12 August 2025 11:59:17 os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 nodename: zzc-IdeaPad-15sALC-2021 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 12 current working directory: /home/zzc/web_Django/myproject writing pidfile to /home/zzc/web_Django/myproject/uwsgi.pid detected binary path: /www/server/pyporject_evn/睿进之眼/bin/uwsgi setgid() to 1000 set additional group 4 (adm) set additional group 24 (cdrom) set additional group 27 (sudo) set additional group 30 (dip) set additional group 46 (plugdev) set additional group 122 (lpadmin) set additional group 135 (lxd) set additional group 136 (sambashare) setuid() to 1000 chdir() to /home/zzc/web_Django/myproject your processes number limit is 71072 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 0.0.0.0:18999 fd 4 uwsgi socket 0 bound to TCP address 127.0.0.1:34993 (port auto-assigned) fd 3 Python version: 3.13.2 (main, Aug 12 2025, 19:45:25) [GCC 11.4.0] Python main interpreter initialized at 0x580c36707f70 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 703600 bytes (687 KB) for 8 cores *** Operational MODE: preforking+threaded *** Traceback (most recent call last): File "/home/zzc/web_Django/myproject/myproject/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: 119989) spawned uWSGI worker 1 (pid: 119990, cores: 2) spawned uWSGI worker 2 (pid: 119991, cores: 2) spawned uWSGI worker 3 (pid: 119992, cores: 2) spawned uWSGI worker 4 (pid: 119993, cores: 2) spawned uWSGI http 1 (pid: 119994) [uWSGI] getting INI configuration from /home/zzc/web_Django/myproject/uwsgi.ini *** Starting uWSGI 2.0.30 (64bit) on [Wed Aug 13 15:02:56 2025] *** compiled with version: 11.4.0 on 12 August 2025 11:59:17 os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 nodename: zzc-IdeaPad-15sALC-2021 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 12 current working directory: /home/zzc/web_Django/myproject writing pidfile to /home/zzc/web_Django/myproject/uwsgi.pid detected binary path: /www/server/pyporject_evn/睿进之眼/bin/uwsgi setgid() to 1000 set additional group 4 (adm) set additional group 24 (cdrom) set additional group 27 (sudo) set additional group 30 (dip) set additional group 46 (plugdev) set additional group 122 (lpadmin) set additional group 135 (lxd) set additional group 136 (sambashare) setuid() to 1000 chdir() to /home/zzc/web_Django/myproject your processes number limit is 71072 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 0.0.0.0:18999 fd 4 uwsgi socket 0 bound to TCP address 127.0.0.1:33967 (port auto-assigned) fd 3 Python version: 3.13.2 (main, Aug 12 2025, 19:45:25) [GCC 11.4.0] Python main interpreter initialized at 0x6408652e2f70 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 703600 bytes (687 KB) for 8 cores *** Operational MODE: preforking+threaded *** Traceback (most recent call last): File "/home/zzc/web_Django/myproject/myproject/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: 169369) spawned uWSGI worker 1 (pid: 169370, cores: 2) spawned uWSGI worker 2 (pid: 169371, cores: 2) spawned uWSGI worker 3 (pid: 169372, cores: 2) spawned uWSGI worker 4 (pid: 169373, cores: 2) spawned uWSGI http 1 (pid: 169374) --- no python application found, check your startup logs for errors --- [pid: 169372|app: -1|req: -1/1] 192.168.31.19 () {38 vars in 847 bytes} [Wed Aug 13 15:03:42 2025] GET / => generated 21 bytes in 0 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: 169372|app: -1|req: -1/2] 192.168.31.19 () {38 vars in 807 bytes} [Wed Aug 13 15:03:43 2025] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 1) --- no python application found, check your startup logs for errors --- [pid: 169372|app: -1|req: -1/3] 192.168.31.19 () {38 vars in 847 bytes} [Wed Aug 13 15:24:03 2025] GET / => generated 21 bytes in 0 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: 169373|app: -1|req: -1/4] 192.168.31.19 () {38 vars in 807 bytes} [Wed Aug 13 15:24:05 2025] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0) [uWSGI] getting INI configuration from /home/zzc/webbi/myproject/uwsgi.ini *** Starting uWSGI 2.0.30 (64bit) on [Wed Aug 13 16:59:15 2025] *** compiled with version: 11.4.0 on 12 August 2025 11:59:17 os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 nodename: zzc-IdeaPad-15sALC-2021 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 12 current working directory: /home/zzc/webbi/myproject writing pidfile to /home/zzc/webbi/myproject/uwsgi.pid detected binary path: /www/server/pyporject_evn/睿进之眼/bin/uwsgi setgid() to 1001 setuid() to 1001 chdir() to /home/zzc/webbi/myproject your processes number limit is 71072 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 0.0.0.0:8000 fd 4 uwsgi socket 0 bound to TCP address 127.0.0.1:40783 (port auto-assigned) fd 3 Python version: 3.13.2 (main, Aug 12 2025, 19:45:25) [GCC 11.4.0] Python main interpreter initialized at 0x626f41fdaf70 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 703600 bytes (687 KB) for 8 cores *** Operational MODE: preforking+threaded *** Traceback (most recent call last): File "/home/zzc/webbi/myproject/myproject/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: 177885) spawned uWSGI worker 1 (pid: 177886, cores: 2) spawned uWSGI worker 2 (pid: 177887, cores: 2) spawned uWSGI worker 3 (pid: 177888, cores: 2) spawned uWSGI worker 4 (pid: 177889, cores: 2) spawned uWSGI http 1 (pid: 177890) --- no python application found, check your startup logs for errors --- [pid: 177888|app: -1|req: -1/1] 192.168.31.19 () {42 vars in 906 bytes} [Wed Aug 13 17:06:12 2025] GET / => generated 21 bytes in 0 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: 177886|app: -1|req: -1/2] 192.168.31.19 () {38 vars in 845 bytes} [Wed Aug 13 17:06:13 2025] GET / => generated 21 bytes in 0 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: 177886|app: -1|req: -1/3] 192.168.31.19 () {40 vars in 876 bytes} [Wed Aug 13 17:06:36 2025] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 1) [uWSGI] getting INI configuration from /home/zzc/webbi/myproject/uwsgi.ini *** Starting uWSGI 2.0.30 (64bit) on [Thu Aug 14 11:32:57 2025] *** compiled with version: 11.4.0 on 12 August 2025 11:59:17 os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 nodename: zzc-IdeaPad-15sALC-2021 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 12 current working directory: /home/zzc/webbi/myproject writing pidfile to /home/zzc/webbi/myproject/uwsgi.pid detected binary path: /www/server/pyporject_evn/睿进之眼/bin/uwsgi setgid() to 1001 setuid() to 1001 chdir() to /home/zzc/webbi/myproject your processes number limit is 71072 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 0.0.0.0:8000 fd 4 uwsgi socket 0 bound to TCP address 127.0.0.1:42601 (port auto-assigned) fd 3 Python version: 3.13.2 (main, Aug 12 2025, 19:45:25) [GCC 11.4.0] Python main interpreter initialized at 0x5e3342bfaf70 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 703600 bytes (687 KB) for 8 cores *** Operational MODE: preforking+threaded *** Traceback (most recent call last): File "/home/zzc/webbi/myproject/myproject/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: 217377) spawned uWSGI worker 1 (pid: 217378, cores: 2) spawned uWSGI worker 2 (pid: 217379, cores: 2) spawned uWSGI worker 3 (pid: 217380, cores: 2) spawned uWSGI worker 4 (pid: 217381, cores: 2) spawned uWSGI http 1 (pid: 217382) --- no python application found, check your startup logs for errors --- [pid: 217378|app: -1|req: -1/1] 192.168.31.19 () {42 vars in 907 bytes} [Thu Aug 14 11:33:49 2025] GET / => generated 21 bytes in 0 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: 217378|app: -1|req: -1/2] 192.168.31.19 () {38 vars in 845 bytes} [Thu Aug 14 11:33:49 2025] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 1) --- no python application found, check your startup logs for errors --- [pid: 217379|app: -1|req: -1/3] 192.168.31.19 () {38 vars in 804 bytes} [Thu Aug 14 11:33:50 2025] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0) [uWSGI] getting INI configuration from /home/zzc/webbi/myproject/uwsgi.ini *** Starting uWSGI 2.0.30 (64bit) on [Thu Aug 14 11:46:03 2025] *** compiled with version: 11.4.0 on 12 August 2025 11:59:17 os: Linux-6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 nodename: zzc-IdeaPad-15sALC-2021 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 12 current working directory: /home/zzc/webbi/myproject writing pidfile to /home/zzc/webbi/myproject/uwsgi.pid detected binary path: /www/server/pyporject_evn/睿进之眼/bin/uwsgi setgid() to 1001 setuid() to 1001 chdir() to /home/zzc/webbi/myproject your processes number limit is 71072 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 0.0.0.0:8000 fd 4 uwsgi socket 0 bound to TCP address 127.0.0.1:36627 (port auto-assigned) fd 3 Python version: 3.13.2 (main, Aug 12 2025, 19:45:25) [GCC 11.4.0] Python main interpreter initialized at 0x5dd863e03f70 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 703600 bytes (687 KB) for 8 cores *** Operational MODE: preforking+threaded *** Traceback (most recent call last): File "/home/zzc/webbi/myproject/myproject/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: 218691) spawned uWSGI worker 1 (pid: 218692, cores: 2) spawned uWSGI worker 2 (pid: 218693, cores: 2) spawned uWSGI worker 3 (pid: 218694, cores: 2) spawned uWSGI worker 4 (pid: 218695, cores: 2) spawned uWSGI http 1 (pid: 218696) --- no python application found, check your startup logs for errors --- [pid: 218695|app: -1|req: -1/1] 127.0.0.1 () {52 vars in 1167 bytes} [Thu Aug 14 11:49:02 2025] GET / => generated 21 bytes in 0 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: 218693|app: -1|req: -1/2] 127.0.0.1 () {50 vars in 1098 bytes} [Thu Aug 14 11:49:02 2025] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)怎么解决
最新发布
08-15
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值