4

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

对于我已经实现的宁静请求,它似乎工作正常,但我无法访问我的 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/ 的管理界面。

我认为我实例化烧瓶管理员的方式存在问题。我保留了默认的“admin/”url,但也许我需要在生产时声明一个特定的 url?

谢谢你的帮助。

编辑 :

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

4

1 回答 1

0

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

@app.route('/')
@app.route('/myapp/')
def index():
于 2015-04-16T21:45:54.737 回答