在Manjaro(Arch)上通过Apache2虚拟主机+mod_wsgi部署Flask应用求助
Hey there, let's get your Flask app up and running with mod_wsgi on Apache 2.4 in Manjaro. I’ll walk through the most common pitfalls and fixes based on your setup:
Arch-based distros like Manjaro sometimes have mod_wsgi linked to a different Python version by default. Let’s verify and fix this:
- First, check which Python version mod_wsgi is using:
Look for themod_wsgi-express module-configPythonPathline—if it doesn’t point to Python 3.6’s directory, you’ll need to install a version of mod_wsgi compiled for 3.6. - Install mod_wsgi via pip for Python 3.6:
pip3.6 install mod_wsgi - Run
mod_wsgi-express module-configagain, then copy the three output lines (starting withLoadModule,WSGIPythonHome,WSGIPythonPath) and add them to your Apache config file (usually/etc/httpd/conf/httpd.confor a new file in/etc/httpd/conf.d/).
Let’s adjust your Apache virtual host to ensure it points correctly to your app and grants proper permissions:
- Here’s a corrected example configuration tailored to your setup:
<VirtualHost *:80> # Replace with your actual domain or server IP ServerName dashboard.yourdomain.com # Define a daemon process for your app, pointing to the app directory WSGIDaemonProcess sonntag-dashboard python-path=/srv/http/dashboard WSGIProcessGroup sonntag-dashboard # Map the root URL to your WSGI script WSGIScriptAlias / /srv/http/dashboard/wsgi.py # Grant Apache access to the app directory <Directory /srv/http/dashboard> Require all granted </Directory> # Logging for debugging ErrorLog /var/log/httpd/dashboard-error.log CustomLog /var/log/httpd/dashboard-access.log combined </VirtualHost> - If you’re using a Python virtual environment for your Flask app, add
python-home=/srv/http/dashboard/your-venvto theWSGIDaemonProcessline (replaceyour-venvwith your actual venv directory).
Ensure your wsgi.py (in /srv/http/dashboard) is set up correctly to expose your Flask app:
import sys # Add the app directory to Python's path to ensure it finds SonntagDashboard sys.path.insert(0, '/srv/http/dashboard') # Import your Flask app instance and rename it to 'application' (required by mod_wsgi) from SonntagDashboard import app as application # Important: Disable debug mode in production! # application.debug = True
Apache runs as the http user in Manjaro, so it needs access to your app files:
# Give ownership to the Apache user/group chown -R http:http /srv/http/dashboard # Set readable/execute permissions for the directory chmod -R 755 /srv/http/dashboard
- First, check for config syntax errors:
apachectl configtest - If everything looks good, restart Apache to apply changes:
systemctl restart httpd - If you still run into issues, check the error logs for details:
cat /var/log/httpd/dashboard-error.log # Or view system logs for Apache journalctl -u httpd -f
These steps should resolve most common deployment issues with Flask + mod_wsgi on Manjaro. Let me know if you hit specific error messages we can troubleshoot further!
内容的提问来源于stack exchange,提问作者Basti

