问题
I am trying to deploy my Flask app using Apache and mod_wsgi on an Ubuntu server.
It seems to work fine for restful requests that I have implemented, but I can't access my Flask-Admin pages (which I can access in development).
Here is the structure of my app (simplified for the purpose of this question) :
- MyApp/
- main.py
- myapp/
- __init__.py
- Views.py
- files/
- wsgi/
myapp.wsgi
When in development, I simply run by using python main.py and everything works fine.
Here is the wsgi file :
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
Here is the configuration file for Apache, I'm using 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>
Here is how I instantiate the Flask app in my __ init __.py :
app = Flask(__name__, static_folder='files')
Here is how I create the Admin interface in my main.py :
# Create admin
admin = admin.Admin(app, 'App Administration')
I also have a link to the admin page in my Views.py :
@app.route('/')
def index():
return '<a href="/admin/">Go to admin page</a>'
When in development, I can access the admin interface at mysite.com/admin/ .
In production, I have my app at mysite.com/myapp/ and I can't access the admin interface, which I expected to be at mysite.com/myapp/admin/ .
I think there's a problem with the way I instantiate flask-admin. I kept the default "admin/" url but maybe I need to declare a specific url when in production ?
Thanks for any help.
EDIT :
I checked the Apache error log but I don't get any error.
回答1:
Did you try to update your route with "myapp"? Looks like you need to update your route for production. May even be able to drop the '/' on production. Try it.
@app.route('/')
@app.route('/myapp/')
def index():
来源:https://stackoverflow.com/questions/26585050/flask-admin-pages-inaccessible-in-production