使用带有Apache和sqlalchemy的Flask部署应用程序

时间:2016-06-21 17:17:29

标签: apache flask sqlalchemy redhat

我有一个使用Flask开发的Web应用程序,现在我正在尝试在运行apache的RedHat服务器上进行部署。我想我已经将问题缩小到我的SQL Server(在另一台机器上)和Apache / Flask方面之间的通信错误。如果我在其上运行烧瓶应用程序而不是通过apache,则没有问题。如果我消除了与服务器的连接,那么Apache使用Flask提供非SQL依赖页面没有问题。当我尝试一起运行它时,网站将无法加载。它只是说它在网站上等待,直到它超时。

我的WSGI文件:

#/var/www/wsgi-scripts/cfwebapp.wsgi

import os,sys
sys.path.insert(0,'/var/www/cfwebapp')

activate_this = '/var/www/.virtualenvs/cfwebapp/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

from flask import Flask

from cfwebapptest import app as application

我的烧瓶应用

from flask import Flask, render_template, request,redirect,session,jsonify, Response, send_file, url_for
import pymssql
from sqlalchemy import *
from sqlalchemy.sql import and_, or_, not_, text
from sqlalchemy.orm import create_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

#Create an engine and get the metadata
Base = declarative_base()
connection_string = r"mssql+pymssql://{0}:{1}@172.XX.XXX.XXX/CashFlow".format(
'cashflow','password')
engine= create_engine(connection_string)
metadata = MetaData(bind=engine)
Session = sessionmaker(bind=engine)

#Reflect each database table we need to use, using metadata
class Users(Base):
    __table__ = Table('users', metadata, autoload=True)

class Assignments(Base):
    __table__ = Table('assignments', metadata, autoload=True)


app = Flask(__name__)

@app.route('/')
@app.route('/signin')
def showSignin():
    if session.get('user'):
        return render_template('userHome.html')
    else:
        return render_template('signin.html')

@app.route('/userHome')
def userHome():
    if session.get('user'):
        return render_template('userHome.html')
    else:
        return render_template('error.html',error = 'Unauthorized Access')

@app.route('/logout')
def logout():
    sqlsession=Session()
    temptext='table'+session['user']
    sqlsession.execute("DROP TABLE "+temptext)
    sqlsession.commit()
    sqlsession.close()
    session.clear()
    session.pop('user',None)
    return redirect('/')

@app.route('/validateLogin',methods=['POST'])
def validateLogin():
    sqlsession = create_session(bind=engine)
    username = request.form['inputUserID']
    userpass = request.form['inputPassword']
    try:
        query=sqlsession.query(Users).filter(Users.user_name==username, Users.password==userpass).one()
        if query.user_name==username:
            session['logged_in']=True
            session['user']=username
            return redirect('/userHome')
        else:
            return render_template('error.html', error='Wrong email address or password.')
    except:
        return render_template('error.html',error = 'Wrong email address or password.')

if __name__ == "__main__":
    app.secret_key = 'super secret key'
    app.config['SESSION_TYPE'] = 'filesystem'
    app.run()

这是我的Apache错误日志:

[Tue Jun 21 12:38:17.316702 2016] [mpm_prefork:notice] [pid 8319] AH00170: caught SIGWINCH, shutting down gracefully
[Tue Jun 21 12:38:18.437008 2016] [suexec:notice] [pid 8563] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe8f:18a0. Set the 'ServerName' directive globally to suppress this message
[Tue Jun 21 12:38:18.462782 2016] [auth_digest:notice] [pid 8563] AH01757: generating secret for digest authentication ...
[Tue Jun 21 12:38:18.463304 2016] [lbmethod_heartbeat:notice] [pid 8563] AH02282: No slotmem from mod_heartmonitor
[Tue Jun 21 12:38:18.494560 2016] [mpm_prefork:notice] [pid 8563] AH00163: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/5.4.16 mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Tue Jun 21 12:38:18.494588 2016] [core:notice] [pid 8563] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

0 个答案:

没有答案