如何在PythonAnywhere上通过uWSGI+nginx部署Apache Superset?
Hey there! I’ve tackled this exact setup on PythonAnywhere before, so let me break down the steps to get your Superset instance running smoothly behind uWSGI and Nginx—PythonAnywhere handles the core Nginx/uWSGI layer for you, we just need to wire up Superset properly.
Step 1: Create a Custom WSGI Entry File
Superset is built on Flask, so we need a simple file to point PythonAnywhere’s uWSGI setup to Superset’s Flask app. Make a wsgi.py file in your project root (e.g., /home/yourusername/superset/wsgi.py) with this code:
from superset.app import create_app # Initialize the Superset Flask application app = create_app() # Optional: For local testing (won't execute on PythonAnywhere) if __name__ == "__main__": app.run(host="0.0.0.0", port=8088)
Step 2: Configure Your PythonAnywhere Web App
- Head to your PythonAnywhere Dashboard, click the Web tab, then hit Add a new web app.
- Choose Manual configuration (skip the pre-built framework options), then select the Python version that matches your Superset virtual environment.
- In the Virtualenv section, paste the full path to your Superset virtual environment (e.g.,
/home/yourusername/.virtualenvs/superset-venv) and click Reload to apply this.
Step 3: Update the WSGI Configuration File
In the Code section of your web app settings, click the link to the auto-generated WSGI config file (it’ll look like /var/www/yourusername_pythonanywhere_com_wsgi.py). Replace its contents with:
import sys import os # Add your Superset project directory to Python's path sys.path.insert(0, '/home/yourusername/superset') # Activate the virtual environment activate_this = '/home/yourusername/.virtualenvs/superset-venv/bin/activate_this.py' with open(activate_this) as file_: exec(file_.read(), dict(__file__=activate_this)) # Import the Superset Flask app as the WSGI application from wsgi import app as application
Step 4: Serve Superset’s Static Files
Superset relies on static assets (CSS, JS, icons) that need to be served directly by Nginx. In the Static files section of your web app settings:
- Add a new entry with URL set to
/static/ - Set the Directory to the static folder inside your Superset virtual environment. For example, if you’re using Python 3.9, this path would be:
/home/yourusername/.virtualenvs/superset-venv/lib/python3.9/site-packages/superset/static
Step 5: Final Checks & Reload
Before reloading, double-check these critical Superset configs in your superset_config.py:
- Ensure
SECRET_KEYis set to a secure, random string (this is mandatory for production deployments) - Confirm your metadata database connection is correctly configured (Superset needs to access this to store dashboards and user data)
- If you want to allow public access to certain features, set
PUBLIC_ROLE_LIKE_GAMMA = True(adjust based on your security needs)
Once that’s sorted, click Reload yourusername.pythonanywhere.com at the top of the web app settings page. Navigate to your PythonAnywhere domain, and you should see the Superset login page ready to go!
内容的提问来源于stack exchange,提问作者tmo

