【问题标题】:Flask-Admin pages inaccessible in productionFlask-Admin 页面在生产中无法访问
【发布时间】:2014-12-22 11:36:03
【问题描述】:

我正在尝试在 Ubuntu 服务器上使用 Apache 和 mod_wsgi 部署我的 Flask 应用程序。

对于我已经实现的 restful 请求,它似乎工作正常,但我无法访问我的 Flask-Admin 页面(我可以在开发中访问)。

这是我的应用程序的结构(为了解决这个问题而进行了简化):

- MyApp/
    - main.py
    - myapp/
        - __init__.py
        - Views.py
        - files/
    - wsgi/
        myapp.wsgi

在开发时,我只是使用 python main.py 运行,一切正常。

这是 wsgi 文件:

import sys
import os

##Virtualenv Settings
activate_this = '/var/www/code/MyApp/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

##Replace the standard out
sys.stdout = sys.stderr

##Add this file path to sys.path in order to import settings
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '../..'))

##Add this file path to sys.path in order to import app
sys.path.append('/var/www/code/MyApp/')

from myapp import app as application

这是 Apache 的配置文件,我使用的是 Apache 2.2:

<VirtualHost *:443>
        WSGIScriptAlias /myapp /var/www/code/MyApp/wsgi/myapp.wsgi
        WSGIScriptReloading On
        WSGIPassAuthorization On

        SSLEngine on
        SSLCertificateFile /var/www/code/MyApp/ssl.crt
        SSLCertificateKeyFile /var/www/code/MyApp/ssl.key
        SSLVerifyClient None
        SSLOptions +StdEnvVars

        <Directory /var/www/code/MyApp/wsgi>
                Order deny,allow
                Allow from all
        </Directory>

</VirtualHost>

这是我在 __ init __.py 中实例化 Flask 应用程序的方法:

app = Flask(__name__, static_folder='files')

这是我在 main.py 中创建管理界面的方法:

# Create admin
admin = admin.Admin(app, 'App Administration')

我的 Views.py 中还有一个指向管理页面的链接:

@app.route('/')
def index():
    return '<a href="/admin/">Go to admin page</a>'

在开发过程中,我可以访问 mysite.com/admin/ 上的管理界面。

在生产中,我的应用程序位于 mysite.com/myapp/,但我无法访问管理界面,我预计该界面位于 mysite.com/myapp/admin/。

我认为我实例化 flask-admin 的方式存在问题。我保留了默认的“admin/”网址,但也许我需要在生产时声明一个特定的网址?

感谢您的帮助。

编辑:

我检查了 Apache 错误日志,但没有收到任何错误。

【问题讨论】:

  • 不相关,但不需要使用“sys.stdout = sys.stderr”行,除非您使用的 mod_wsgi 版本比 Linux 发行版使用的更古老。

标签: apache flask wsgi flask-admin


【解决方案1】:

您是否尝试使用“myapp”更新您的路线?看起来您需要更新生产路线。甚至可以在生产中删除“/”。试试看。

@app.route('/')
@app.route('/myapp/')
def index():

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    相关资源
    最近更新 更多