revised: 25-Dec-2021
Part D1: Establish 'myproject.service' is active
Part D2. Configuring Nginx to serve Flask
Assumption: Nginx Webserver is installed and Webmin configured for adjustments on Nginx. If the Nginx module is not installed in Webmin, see the following: iRedMail-Extras-PartA
Step01: Configure Nginx to Proxy to uWSGI
Enter Webmin [https://MySeverIP:10000] and go to [Servers]-> [Nginx Webserver]->[YourDomain eg.example.com]. Change the server block script similar to this, but changing the domain (example.com) to your own domain:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com www.example.com;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/sammy/myproject/myproject.sock;
}
ssl_certificate /etc/ssl/certs/iRedMail.crt;
ssl_certificate_key /etc/ssl/private/iRedMail.key;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log info;
}
Restart Nginx, open the browser with your domain (eg.https://example.com)
The same msg 'Hello There!' should appear in red. To serve the 3-page website (assuming you have synchonized the files to the server) do the following:
Note: Remember restart systemctl service whenever changes to the website pages are made.
Reference: how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04
Notes for the mail-enhanced site:
Two remaining steps are required as follows;
1. Modify the settings in 'project.py' by changing 'example.com' with one's own domain and modifying the 'SECRET_KEY'
2. Create the mailbox: info@yourdomain.com via the 'iredadmin' page.
1. Via Webmin->Apache2 Webserver->Global Configuration->Global Modules: Click/Activate the module: proxy-uWSGI
2. Via Webmin->Apache2 Webserver->Existing Virtual Host: Click on 'Virtual Server [port:80] and edit the 'Directives' with two changes;
2.a Comment out with a '#' the line: DocumentRoot /var/www/html
2.b Add below it this line: ProxyPass / unix:/home/sammy/myproject/myproject.sock|uwsgi://uwsgi-uds-app1/
Restart the webserver and browser to your IP or, if you have established it, to your domain (eg. http://[MyIP-address or myexample.com])
| Flask | Flask-PartB |
| Flask-PartC | Flask-PartD |