How to deploy websites on a remote server
How to deploy your websites on your remote server?
It is a good idea to use your remote server to host your websites. Play around in my website. This blog takes a Flask app as an example.
Conponents: Flask, Nginx, Gunicorn
1. Set up a virtual environment
- Use Anaconda to set up a virtual environment
- Install dependencies
conda create -n env_name python
conda activate env_name
pip install -r requirements.txt
2. Set up Nginx and Gunicon
- Create the configuration files and set up accronding to your app.
code /etc/nginx/conf.d/flaskapp.conf
code /etc/systemd/system/flaskapp.service
3. Ensure permissions for your app folder
- It is suggested not to run your website as the
root
user.
sudo chown -R $USER:$USER /path/to/your/app
sudo chmod -R 755 /path/to/your/app
sudo chmod -R 666 /path/to/your/app
4. Ensure the firewall and ports
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
5. Restart Nginx and your Flask app
sudo nginx -t
sudo systemctl restart nginx
sudo systemctl daemon-reload
sudo systemctl enable your_app
sudo systemctl restart your_app
6. Check running services
sudo systemctl status your_app
sudo systemctl status nginx
Now it is done!