On a raspberry pi 3 I am trying to deploy a Flask application on apache server. This application is going to be accessible by a custom internal network domain called darts.loc.
The structure of the application is as following:
/var/www/darts
└── darts
├── dartsapp
│ ├── api
│ │ └── resources
│ │
│ ├── static
│ │ ├── css
│ │ ├── fonts
│ │ ├── images
│ │ └── js
│ ├── templates
│ │
│ │
│ │
│ │
│ │
│ │
│ ├── uploads
│ └── website
└── venv
In /var/www/darts/darts I have an __init__.py
file with the following content:
from dartsapp import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)
What should I update in my darts.conf and darts.wsgi files so that I can get the application running?
The current structure is as following:
darts.conf:
<VirtualHost *:443>
ServerName darts.loc
ServerAdmin [email protected]
WSGIScriptAlias / /var/www/darts/darts.wsgi
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
<Directory /var/www/darts/darts>
AddDefaultCharset utf-8
SetEnv PYTHONIOENCODING utf8
Order allow,deny
Allow from all
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Alias /dartsapp /var/www/darts/darts/dartsapp
<Directory /var/www/darts/darts/dartsapp>
Order allow,deny
Allow from all
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Alias /templates /var/www/darts/darts/dartsapp/templates
<Directory /var/www/darts/darts/dartsapp/templates/>
Order allow,deny
Allow from all
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Alias /static /var/www/darts/darts/dartsapp/static
<Directory /var/www/darts/darts/dartsapp/static/>
Order allow,deny
Allow from all
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Alias /uploads /var/www/darts/darts/dartsapp/uploads
<Directory /var/www/darts/darts/dartsapp/uploads/>
Order allow,deny
Allow from all
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
darts.wsgi file (under /var/www/darts):
#!/var/www/darts/darts/venv/bin/python3.10/
import sys
#sys.path.append('/var/www/darts/darts/venv/lib/python3.10/site-packages/')
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/darts/darts/")
from darts import app as application
2
Answers
I managed to run everything by adding two changes.
The darts.wsgi file now looks like this:
and in the darts.conf file I have added
Seems to be working for now.
I found that if I run WSGI in daemon mode then the wsgi file can be really
simple, and the apache config is only a big more complex.
Presuming your apps folder is called darts, and you use
app=Flask(__name__)
to define your app.Here is the simplified apache config