I am trying to deploy a Flask application on port 80 using Ubuntu22.04, Apache2 and Gunicorn. I am using unix .sock file created by gunicorn.
I have subsequently followed an online tutorial but with the same result:
https://medium.com/@thishantha17/build-a-simple-python-rest-api-with-apache2-gunicorn-and-flask-on-ubuntu-18-04-c9d47639139b
The application runs successfully from systemd .service file:
[Unit]
Description=Gunicorn instance to serve flask application
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/simon/flask_rest/
Environment="PATH=/home/simon/flask_rest/flaskvenv/bin"
ExecStart=/home/simon/flask_rest/flaskvenv/bin/gunicorn --config gunicorn_config.py wsgi:app
[Install]
WantedBy=multi-user.target
When I try to run from Apache2 I get a 503 error when trying to run a post request. Checking the logs in /var/log/apache2/flaskrest-error.log and get a proxy error:
proxy:error (13) permission denied – failed to make connection to unix web socket /home/simon/flask_rest/flaskrest.sock
proxy_http:error HTTP: failed to make connection to backend: httpd-UDS
My Apache2 config is as follows:
”’
<VirtualHost *:80>
# ServerAdmin root@ubuntu
ErrorLog ${APACHE_LOG_DIR}/flaskrest-error.log
CustomLog ${APACHE_LOG_DIR}/flaskrest-access.log combined
<Location />
ProxyPass unix:/home/simon/flask_rest/flaskrest.sock|http://127.0.0.1/
ProxyPassReverse unix:/simon/root/flask_rest/flaskrest.sock|http://127.0.0.1/
</Location>
”’
Why am I unable to connect via Apache2 using the reverse proxy?
Additionally, I have allowed Apache and Apache (v6) within utw.
Many thanks for any help.