我正在尝试使用Phusion的Passenger和flask
在centos7上部署Nginx
应用程序。我可以在服务器上的flask中运行我的应用程序,但无法访问该应用程序。
我已按照phusion guide
Flask
应用的创建过程如下:
import os
from flask import Flask, send_from_directory
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
DATABASE_FILE = os.path.join(app.instance_path, "myapp.sqlite")
app.config.from_mapping(
SECRET_KEY="key",
SQLALCHEMY_DATABASE_URI='mysql+mysqldb://user:password@localhost:3306/db',
SQLALCHEMY_TRACK_MODIFICATIONS=False,
FLASK_ADMIN_SWATCH= 'cerulean',
)
if test_config is None:
app.config.from_pyfile("config.py", silent=True)
else:
app.config.from_mapping(test_config)
try:
os.makedirs(app.instance_path)
except OSError:
pass
@app.route("/favicon.ico")
def favicon():
return send_from_directory(
os.path.join(app.root_path, "static/favicon"),
"favicon.ico",
mimetype="image/vnd.microsoft.icon",
)
from myapp.model.auth_model import db
db.init_app(app)
from myapp.controller import session
session.init_app(app)
from myapp.view import auth
app.register_blueprint(auth.bp)
from myapp.view import module1
app.register_blueprint(module1.bp)
app.add_url_rule("/", endpoint="index")
from myapp.view import api
app.register_blueprint(api.bp)
return app
对于旅客WSGI文件(passenger_wsgi.py
),我没有更好的主意,只是将此代码放在了应用程序文件夹中:
import myapp
application = myapp.create_app()
nginx error.log
显示以下内容
App 5979 output: File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 333, in process_request
App 5979 output: result = self.app(env, start_response)
App 5979 output: TypeError: 'module' object is not callable
帮助!!!!!
答案 0 :(得分:0)
我成功部署了该应用程序。 我必须做三件事:
应用工厂现在是这里...
...
from myapp.view import auth
app.register_blueprint(auth.bp)
from myapp.view import module1
app.register_blueprint(module1.bp)
app.add_url_rule("/", endpoint="index")
from myapp.view import api
app.register_blueprint(api.bp)
return app
if __name__ == "__main__":
app = create_app()
app.run()
/var/www/app_name/code/passenger_wsgi.py文件如下
from nwpapp import create_app
application = create_app()
我没有使用虚拟环境。默认情况下,将调用python2.7。我必须设置替代方法并将python3.6设置为默认值。确保运行正确的pip版本以安装依赖项。