我想在Ubuntu服務器上使用Apache和mod_wsgi部署我的Flask應用程序。在生產中無法訪問的Flask-Admin頁面
它似乎對我已經實施的寧靜請求正常工作,但我無法訪問我的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:
app = Flask(__name__, static_folder='files')
這裏是我的CR eate管理界面在我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 /」url,但也許我需要在生產中聲明特定的url?
感謝您的任何幫助。
編輯:
我檢查Apache的錯誤日誌,但我沒有得到任何錯誤。
不相關,但不需要'sys.stdout = sys.stderr'這一行,除非您使用的是比Linux發行版更古老的mod_wsgi版本。 – 2015-04-17 00:10:01