【发布时间】:2015-08-17 23:19:05
【问题描述】:
我有一个使用 Python3 和 Flask 的应用程序,并希望使用 virtualenv 将其部署在 uwsgi 和 nginx 上。
# Brieffenster
location /projekte/brieffenster {
include uwsgi_params;
uwsgi_pass unix:///tmp/brieffenster.sock;
}
和
[uwsgi]
plugin = python3
socket = /tmp/brieffenster.sock
chown-socket = www-data:www-data
chdir = /var/www/projekte/brieffenster
virtualenv = /var/www/projekte/brieffenster/.env
mount = /projekte/brieffenster=brieffenster.py
callable = app
manage-script-name = true
在 http://<SERVER_IP>/projekte/brieffenster/ 上运行 HTTP GET 会返回 502 Bad Gateway。
当我使用
从命令行启动它时sudo uwsgi --ini /etc/uwsgi/apps-enabled/brieffenster.ini
有一个堆栈跟踪(见下文)。我已经调试了几个小时,我认为我做的一切都是正确的。
我有什么遗漏吗?
$ sudo uwsgi --ini /etc/uwsgi/apps-enabled/brieffenster.ini
[uWSGI] getting INI configuration from /etc/uwsgi/apps-enabled/brieffenster.ini
*** Starting uWSGI 1.9.17.1-debian (64bit) on [Mon Aug 17 23:13:01 2015] ***
compiled with version: 4.8.2 on 23 March 2014 17:15:32
os: Linux-2.6.32-042stab094.7 #1 SMP Wed Oct 22 12:43:21 MSK 2014
nodename: bender
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /
detected binary path: /usr/bin/uwsgi-core
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 514091
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 /tmp/brieffenster.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: 3.4.0 (default, Jun 19 2015, 14:24:19) [GCC 4.8.2]
Set PythonHome to /var/www/projekte/brieffenster/.env
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x106f720
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72792 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
mounting brieffenster.py on /projekte/brieffenster
Traceback (most recent call last):
File "/usr/lib/python3.4/pkgutil.py", line 481, in find_loader
spec = importlib.util.find_spec(fullname)
File "/var/www/projekte/brieffenster/.env/lib/python3.4/importlib/util.py", line 100, in find_spec
raise ValueError('{}.__spec__ is None'.format(name))
ValueError: uwsgi_file_brieffenster.__spec__ is None
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "brieffenster.py", line 28, in <module>
app = CustomFlask(__name__)
File "/var/www/projekte/brieffenster/.env/lib/python3.4/site-packages/flask/app.py", line 331, in __init__
instance_path = self.auto_find_instance_path()
File "/var/www/projekte/brieffenster/.env/lib/python3.4/site-packages/flask/app.py", line 622, in auto_find_instance_path
prefix, package_path = find_package(self.import_name)
File "/var/www/projekte/brieffenster/.env/lib/python3.4/site-packages/flask/helpers.py", line 661, in find_package
loader = pkgutil.get_loader(root_mod_name)
File "/usr/lib/python3.4/pkgutil.py", line 467, in get_loader
return find_loader(fullname)
File "/usr/lib/python3.4/pkgutil.py", line 487, in find_loader
raise ImportError(msg.format(fullname, type(ex), ex)) from ex
ImportError: Error while finding loader for 'uwsgi_file_brieffenster' (<class 'ValueError'>: uwsgi_file_brieffenster.__spec__ is None)
更新 1:这是我正在使用的应用程序。它只是一个包罗万象的信息,告诉我请求了哪条路径。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from flask import Flask
__author__ = 'Jonas Gröger <jonas.groeger@gmail.com>'
app = Flask(__name__)
app.config.from_object(__name__)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
return 'You want path: %s' % path
if __name__ == '__main__':
app.run('0.0.0.0')
我正在使用mount 和manage-script-name,因为我计划在/projekte/<folder_name> 中放置更多的Flask 项目。
【问题讨论】:
-
你能展示你的烧瓶应用吗?我想知道'uwsgi_file_brieffenster'..这是从哪里来的?你有那个文件名的导入吗?另外,您使用“不同安装点中的多个烧瓶应用程序”设置的任何原因?你真的有多个烧瓶应用程序在服务器上运行吗?如果您不需要不同的挂载点,有一种更简单的方法来设置 uWSGI。提供更多细节 - 我们会解决这个问题。
-
@GG_Python 我更新了我的帖子,希望能回答你所有的问题:)