![](/img/trans.png)
[英]unable to load configuration from uwsgi when attempting to run flask app via uwsg
[英]no app loaded when starting Flask via uwsgi
我知道這是一個常見問題,但由於我已經搜索了 3 個小時,並且考慮到必須涉及量子奇點,我不得不發布這個。
我不斷收到這個熟悉的錯誤:
[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),
但是,我認為這個非常簡單的設置沒有任何問題。 我的設置:
核心/__init__.py
from flask import Flask
def create_app():
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
return 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"]
啟動.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;
}
}
}
如果我在 DOCKERFILE 中添加 python3 插件RUN apt-get -y install uwsgi nginx uwsgi-plugin-python3
並通過uwsgi --ini uwsgi.ini --plugin python3
運行 uwsgi 我得到:
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'
我不知道這是否是一個暗示。 任何幫助表示贊賞! 謝謝!
睡了8個小時后,我發現了我的錯誤:
通過apt-get
安裝 uwsgi 將不起作用。 需要通過pip install
。 (我的猜測是,這是兩個不同的 uwsgi 實例/服務)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.