我正在尝试使用gunicorn启动烧瓶应用程序,但是我遇到了问题。
从命令行启动它时,可以通过以下命令正常工作:
/usr/local/bin/gunicorn --preload --certfile /etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile /etc/letsencrypt/live/server_name.net/privkey.pem -w 17
-b 0.0.0.0:9090 wsgi:app
.sh脚本中的同一命令会引发错误:
Traceback (most recent call last):
File "/usr/local/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 61, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 221, in run
super(Application, self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 70, in run
Arbiter(self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 118, in setup
self.app.wsgi()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 65, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/util.py", line 372, in import_app
__import__(module)
ImportError: No module named '.0'
cli和.sh都以root用户身份运行。
同一脚本在另一台服务器上可以正常工作,所以我认为环境存在问题。
我尝试在脚本的开头添加以下几行,但没有成功:
$PYTHONPATH=/path/to/my/app
和
$PWD=/path/to/my/app
这是我正在使用的wsgi文件:
from api import app
if __name__ == "__main__":
app.run()
知道可能是什么问题吗?
答案 0 :(得分:0)
我终于能够解决这个问题。以下脚本似乎有效:
cd /path_to_app/
gunicorn --certfile=/etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile=/etc/letsencrypt/live/server_name.net/privkey.pem -w 4 -b 0.0.0.0:9090 wsgi:app