-
Notifications
You must be signed in to change notification settings - Fork 1
Deploy for Production
This guide assumes you that you have walked through the deployment instructions listed on README.md.
Since the server builtin Flask is for test only, which cannot be used as a production server, it is necessary to install another productive server for production usage. This guide will use uWSGI and NGINX as recommendation setup for production.
-
Make sure you have NGINX installed.
-
Follow the descriptions in uWSGI's installing page to install uWSGI to your system. In our case, you should choose to use pip to install it with python support.
-
Create a file named
uwsgi.ini
under the web system's root directory (in this case:/var/www/nottingtable-flask/uwsgi.ini
):
[uwsgi]
module = app:app # callable app object
virtualenv = /var/www/nottingtable-flask/venv # the venv directory of the project
master = true # use master process to control others
processes = 4 # the number of processes
threads = 2 # the number of threads under each process
enable-threads = true
thunder-lock = true
harakiri = 30 # destroy stuck processes
socket = nottingtable.sock # unix socket file
chmod-socket = 660 # socket permission
vacuum = true # auto-delete socket file or log file after shutting down the uWSGI server
disable-logging = True # disable uwsgi's log for performance
die-on-term = true
- Create a systemd file:
/etc/systemd/system/nottingtable.service
[Unit]
Description=uWSGI instance to serve nottingtable
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/nottingtable-flask
Environment="PATH=/var/www/nottingtable-flask/venv/bin"
Environment="DATABASE_URI=mysql+pymysql://[database_user]:[database_password]@[database_address]:[database_port]/[database_name]"
Environment="SERVER_NAME=[Server Domain Name/IP]"
ExecStart=/var/www/nottingtable-flask/venv/bin/uwsgi --ini uwsgi.ini
[Install]
WantedBy=multi-user.target
This systemd unit file allows operation system's init system (systemd
) to manage uWSGI server.
Now, you could try to run this program by systemctl start nottingtable.service
, and use systemctl status nottingtable.service
to monitor its running status. If the status is fine, use systemctl enable nottingtable.service
to make it start at boot.
- Configure NGINX to proxy requests.
Create /etc/nginx/sites-available/nottingtable.conf
:
server {
listen 80;
server_name [server_domain];
location / {
include uwsgi_params;
uwsgi_pass unix:/var/www/nottingtable-flask/nottingtable.sock;
}
}
Then, use soft link to enable that site in NGINX:
ln -s /etc/nginx/sites-available/nottingtable.conf /etc/nginx/sites-enabled
Remember to test the full NGINX configuration: nginx -t
If everything is fine, restart NGINX to let the web system go online: systemctl restart nginx
This guide is adapted from a tutorial on DigitalOcean.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.