Python 如何在OPENSHIFT上部署Flask wsgi应用程序
我有一个flask应用程序,它使用mod_wsgi在vps上运行得非常好。在vps服务器上,我配置虚拟主机 我从github克隆我的项目,并在repo dir中创建wsgi文件。 wsgi: 我有下一个项目结构:Python 如何在OPENSHIFT上部署Flask wsgi应用程序,python,deployment,flask,openshift,wsgi,Python,Deployment,Flask,Openshift,Wsgi,我有一个flask应用程序,它使用mod_wsgi在vps上运行得非常好。在vps服务器上,我配置虚拟主机 我从github克隆我的项目,并在repo dir中创建wsgi文件。 wsgi: 我有下一个项目结构: server.py wsgi --app(folder) --template(folder) --static(folder) --etc(folder) --bin(folder) 当我卷曲我的站点或在浏览器中打开页面时,我得到404响应代码和文本“error” 在openshi
server.py
wsgi
--app(folder)
--template(folder)
--static(folder)
--etc(folder)
--bin(folder)
当我卷曲我的站点或在浏览器中打开页面时,我得到404响应代码和文本“error”
在openshift logs/python.log中,我只有404代码的消息
如何解决此问题或如何正确部署wsgi应用程序。我最近的一个问题是
没有多少帮助,因为noon还没有给任何帮助。。 但无论如何,希望目录树和wsgi.py文件示例能有所帮助
myflaskaws
├── requirements.txt
├── setup.py
├── static
│ ├── assets
│ │ ├── style.css
│ │ └── images
│ │ ├── no.png
│ │ └── yes.png
│ ├── templates
│ ├── index.html
│ ├── login.html
│ ├── searchlist.html
│ ├── update.html
├── test.py
├── test.pyc
└── wsgi.py`
wsgi.py
#!/usr/bin/python
import os
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
from test import app as application
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('localhost', 8051, application)
print("Serving at http://localhost:8051/ \n PRESS CTRL+C to Terminate. \n")
httpd.serve_forever()
print("Terminated!!")
OpenShift Python cartridge希望WSGI脚本文件名为“WSGI.py”,而不仅仅是“WSGI”。通过添加包含WSGI文件的WSGI文件夹解决。从内存中,如果您使用的是
WSGI
目录,则需要将其中的文件名为application
。这是OpenShift支持的一种较旧的设置方式,但现在首选在顶级目录中使用wsgi.py
文件。谢谢。我使用/wsgi/application文件解决了这个问题。我知道wsgi.py,但它不起作用。我还尝试将env变量设置为wsgi.py文件的不同路径。以这种方式,应用程序正在运行,但总是返回404响应代码,并显示文本“error”。现在我的应用程序正在运行,但mysql数据库连接有一些问题。我使用的是tcp套接字,我通过python代码连接到MySQDB,但我无法获得任何数据
#!/usr/bin/python
import os
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
from test import app as application
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('localhost', 8051, application)
print("Serving at http://localhost:8051/ \n PRESS CTRL+C to Terminate. \n")
httpd.serve_forever()
print("Terminated!!")