Finished projects can not always run locally, I was the first deployment project, where the record about the deployment process, for the time being omitted from the pit, after an error encountered issued to finishing.
Ready to work
- A cloud server (here with Ali cloud server, for example, the system installed Centos7)
- Code repository (I use gitee)
Begin deployment
Initialize the system environment
uWSGI not use the root user, so add a new user:
- adduser xxx
- passwd username
- gpasswd -a username wheel (sudo added to the user group)
Switch to the next user to create their own:
- sudo -iu username
Environment Initialization: (ubuntu apt system with the corresponding command line)
- sudo yum install epel-release
- sudo yum install gcc nginx
Install python
Used here is the anaconda, due to the convenient than install python.
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2019.07-Linux-x86_64.sh
Installation file you downloaded, do as the path to its default
- sh Anaconda3-2019.07-Linux-x86_64.sh
To deploy the project to create a virtual environment python
- source anaconda3 / bin / activate (activation Anaconda)
- pip install virtualenv (download slow, then add their own other source)
- mkdir flask_project
- cd flask_project
- Here within your project using git pull down, git is not used in this note-taking range of
- virtualenv venv (to create a virtual environment directory)
- source venv / bin / activate (activates the virtual environment)
- pip install ... (you install the library project used, with requirements.txt more convenient)
UWSGI server configuration
-
pip install uwsgi
-
vim mywsgi.ini (custom server configuration file)
'' '# A simple ini file, additional parameters can check their names
[Uwsgi]
File module = ... # Start program is located
The number of master = true processes = ... # allocation process
threads = ... # Threads
http = 0.0.0.0:5000 # into your own ip and port you want to run
virtualenv = ... # venv just created a path
die-on-term = true
'''
-
uwsgi mywsgi.ini (if you want to use the command uwsgi -d --ini mywsgi.ini instead of running in the background) so far, uwsgi server has started, enter the corresponding ip and port in the browser will be able to visit.
Use nginx reverse proxy
Next came the installation of nginx folder to view nginx.conf content (if not the configuration file, it may be the default file in sites-enabled folder, put different versions of a file or a slightly different location) at http {} section you will see such a sentence: include ..., meaning that files are in this directory are treated as configuration files to load. so, we came to this include the corresponding folder
- vim myconf.conf (create your own configuration)
'' '# Or give simple configuration
server {
listen ...; # you want to listen on port
server_name ...; # your domain name or ip
location / {
include / etc / nginx / uwsgi_params; # this path into the path of your own nginx under uwsgi_params file
uwsgi_pass 0.0.0.0: ....; # specify the same port when just configured mywsgi.ini
}
} '''
- nginx -s reload (reload nginx configuration)
Here, you can specify with nginx configuration address + port to listen to your uwsgi access the server.
Incidentally, if you use nginx, then uwsgi configuration file, http wanted to change the name socket. In addition, if uwsgi not run in the background, you disconnect from the server when the connection uwsgi will automatically shut down if the background is run, it can only be switched off to kill the corresponding process.