yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
# Download the latest version of , Be careful not to use pcre2
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
tar -xvf pcre-8.42.tar.gz
cd pcre-8.42
# Installation and compilation
./configure
make && make install
# see pcre edition
pcre-config --version
# download
wget https://nginx.org/download/nginx-1.15.9.tar.gz
tar -xvf nginx-1.15.9.tar.gz
cd nginx-1.15.9
# Compilation and installation
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.42
make && make install
# View version
/usr/local/webserver/nginx/sbin/nginx -v
# establish Nginx Users who run it www
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
# You can also not create a new user , But use root Users can
# Settings contain multiple profiles , stay nginx.conf Add... At the bottom
include vhost/*.conf;
# start-up
/usr/local/webserver/nginx/sbin/nginx
/usr/local/webserver/nginx/sbin/nginx -s reload # Reload configuration file
/usr/local/webserver/nginx/sbin/nginx -s reopen # restart Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop # stop it Nginx
# /usr/local/webserver/nginx/conf/vhost/demo.tilesrow.com.conf
server
{
# nginx Default listening 80 Port number , You can customize
listen 80;
#listen [::]:80;
# server_name It's the local address
server_name xx.com;
# Static file resources accessed by default
index index.html index.htm index.php default.html default.htm default.php;
root /data/project/demo1;
access_log /usr/local/webserver/nginx/logs/xx.com.log;
}
Intranet mapping port configuration
server
{
listen 80;
#listen [::]:80;
server_name demo.xx.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8001;
}
access_log /usr/local/webserver/nginx/logs/demo.xx.com.log;
}
The result configuration is as follows :
server{
listen 8000;
server_name 192.168.123.201;
location {
include uwsgi_params;
# uwsgi_pass 127.0.0.1:9000;
proxy_pass http://127.0.0.1:9000/;
}
}
Pay attention to python In the virtual environment of the project .
Use pip install gunicorn install gunicorn
After installation, you can start and stop the service by command .
Use the following command to start the project
gunicorn -w 5 -b 127.0.0.1:9000 wsgi:application
among 127.0.0.1:9000 yes flask The boot port of the application and IP,wsgi Is a startup project under the root directory of the project. The file name is wsgi.py application yes flask Instance object name .
Or use custom gunicorn.py The configuration file
gunicorn -c app/gunicorn_config.py wsgi:application
among .py It's a custom profile
as follows :
import multiprocessing
bind = '0.0.0.0:9000' # binding ip And port number
backlog = 512 # Listening to the queue
chdir = '/usr/local/webserver/nginx/software_project' #gunicorn To switch to > working directory
timeout = 40 # Overtime
worker_class = 'gevent' # Use gevent Pattern , You can also use sync Pattern , The default is sync Pattern
workers = multiprocessing.cpu_count() * 2 # Number of processes
threads = 2 # Specify the number of threads to open per process
# Set maximum concurrency
worker_connections = 2000
# Set the process file directory
pidfile = '/var/run/gunicorn.pid'
step :
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install epel-release
yum list | grep python3 | more
yum install python36
python3
It needs to be installed first python3 Environment .
1、 First , Use pip Command to install virtualenv modular :
# pip3 install virtualenv
Test for successful installation
# virtualenv --version
Installation successful , The installed virtualenv Version number of
3、 Create a stand-alone operating environment , And name
# virtualenv --no-site-packages venv
venv Is the name of the virtual environment , You can name it according to your needs .
among Direct use command virtualenv You can create an independent Python Running environment , Add parameters **–no-site-packages**, You can install to the system Python The third-party packages in the environment are not controlled in the independent environment , In this way, we can get a without any third-party packages Python The environment .
4、 New Python The environment is placed in the current directory venv Catalog , With venv This Python Environmental Science , We can start using this virtual environment , It needs to be activated :
# source venv/bin/activate
It should be noted that source In virtual environment bin In the catalog activate , After successful activation , We can see that the name of the virtual environment is added in front of the terminal command prompt
5、 If you don't use this virtual environment for the time being , sign out venv Environmental Science
(venv) # deactivate
6、 Other commands
① View the current virtual machine environment Directory
# worken
② Switch virtual environment
# workon venv2
③ Exit virtual environment
# deactivate
④ Delete virtual environment
# rmvirtualenv venv
Install and configure python A virtual environment virtualenv good after i, Is to install the third-party package required by the project , You can deploy the project to the server .