Setting up a Python Flask application with SSL on a WAMP server in
Windows can be challenging for beginners, but it's a valuable skill for
deploying secure web applications. This step-by-step tutorial will guide you
through the process, from configuring virtual hosts to enabling SSL on your
WAMP server.
Prerequisites
Before starting, ensure you have
the following:
- WAMP server installed on your Windows machine
- Python and Flask installed
- Basic understanding of Apache, virtual hosts, and SSL certificates
Step
1: Setting Up the Project Directory
First, make sure your project
directory is properly structured. For this example, we'll use the following
paths:
- Project directory: C:/wamp64/www/projectdirectory
- Flask app entry point: C:/wamp64/www/projectdirectory/flaskapp.wsgi
- Static files directory: C:/wamp64/www/projectdirectory/static
Step
2: Configuring Virtual Hosts in Apache
Next, you need to configure virtual hosts in Apache to handle different domains and SSL. Open your httpd-vhosts.conf file located at C:/wamp64/bin/apache/apache2.4.59/conf/extra/httpd-vhosts.conf and update it with the following configuration:
<VirtualHost _default_:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes+FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.test
DocumentRoot "c:/wamp64/www/projectdirectory"
WSGIScriptAlias / "c:/wamp64/www/projectdirectory/flaskapp.wsgi"
<Directory "c:/wamp64/www/projectdirectory/">
Require all granted
</Directory>
Alias /static "c:/wamp64/www/projectdirectory/static"
<Directory "c:/wamp64/www/projectdirectory/static/">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName exampledomain.com
Redirect permanent / https://exampledomain.com/
</VirtualHost>
<VirtualHost *:443>
ServerName exampledomain.com
DocumentRoot "c:/wamp64/www/projectdirectory"
WSGIScriptAlias / "c:/wamp64/www/projectdirectory/flaskapp.wsgi"
<Directory "c:/wamp64/www/projectdirectory/">
Require all granted
</Directory>
Alias /static "c:/wamp64/www/projectdirectory/static"
<Directory "c:/wamp64/www/projectdirectory/static/">
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile "c:/wamp64/ssl/certificate.pem"
SSLCertificateKeyFile "c:/wamp64/ssl/key.key"
ErrorLog "c:/wamp64/logs/myapp-error.log"
CustomLog "c:/wamp64/logs/ myapp-access.log" common
</VirtualHost>
Thanks for sharing your feedback! It helps us grow.