我希望使用 Python 3 和 nginx 在虚拟环境中提供一个基本的 Flask 应用程序。但是,当我尝试浏览网页时,出现以下错误:
这里是
我也尝试将
这是
这是
我想我的问题很简单:我做错了什么?
编辑:如果有影响的话:
内部服务器错误
同时,在 /var/log/uwsgi/app/myproj.log
中也看到了错误信息,这让我相信错误出现在我的 uwsgi 配置文件中。nginx 和 uwsgi 似乎通信良好。
这是我的目录结构:
/srv/http/myproj/
|----- setup.py
|----- env/
|----- myproj/
|----- __init__.py
|----- myproj.py
/etc/uwsgi/apps-enabled/
|----- myproj.ini
/etc/nginx/sites-enabled/
|----- myproj
这是我在/var/log/uwsgi/app/myproj.log
中看到的错误:
Thu Jun 8 00:00:41 2017 - *** Operational MODE: preforking ***
Thu Jun 8 00:00:41 2017 - unable to load app 0 (mountpoint='') (callable not found or import error)
Thu Jun 8 00:00:41 2017 - *** no app loaded. going in full dynamic mode ***
Thu Jun 8 00:00:41 2017 - *** uWSGI is running in multiple interpreter mode ***
Thu Jun 8 00:00:41 2017 - spawned uWSGI master process (pid: 14498)
Thu Jun 8 00:00:41 2017 - spawned uWSGI worker 1 (pid: 14504, cores: 1)
Thu Jun 8 00:00:41 2017 - spawned uWSGI worker 2 (pid: 14505, cores: 1)
Thu Jun 8 00:00:43 2017 - --- no python application found, check your startup logs for errors ---
[pid: 14505|app: -1|req: -1/1] 172.16.72.2 () {46 vars in 726 bytes} [Thu Jun 8 00:00:43 2017] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
这里是
/etc/uwsgi/apps-enabled/myproj.ini
文件内容:[uwsgi]
plugins = python3
venv = /srv/http/myproj/env
chdir = /srv/http/myproj
module = myproj:myproj
callable = app
我也尝试将
module
设置为myproj
(在uwsgi日志中没有变化),以及myproj.myproj
(不太成功,因为它找不到模块myproj.myproj
)。这是
/srv/http/myproj/myproj/myproj.py
:import flask
app = flask.Flask(__name__)
这是
/srv/http/myproj/myproj/__init__.py
的内容:from myproj.myproj import app
这里是 /etc/nginx/sites-enabled/myproj
:
upstream myproj {
server unix:///run/uwsgi/app/myproj/socket fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
uwsgi_pass myproj;
include /etc/nginx/uwsgi_params;
}
}
我想我的问题很简单:我做错了什么?
编辑:如果有影响的话:
# lsb_release -d
Description: Ubuntu 16.04.2 LTS
socat - UNIX-CONNECT:/run/uwsgi/app/myproj/socket
和GET / HTTP/1.0
,但出现了“Broken pipe”错误。 - Toddmodule = myproj.myproj
吗?在其中加入冒号看起来不太对,因为应该是一个模块路径。 - Graham Dumpletonmyproj.myproj
。你可能错过了,但我在我的问题中包含了它。 - Todd