Check whether the port number is occupied
netstat -anp | grep 8080
Copy the code
View the application process
ps aux|grep nginx
Copy the code
Flask part
- Flask part
- Flask: First of all, the writing service part is omitted.
Gunicorn part
-
Gunicorn part
-
First of all, our Flask project is started by:
-
app.run(host="0.0.0.0",use_reloader=True, port=5000) Copy the code
-
-
If we use Gunicorn to boot, instead of writing the port number, we can use Gunicorn to set the port number for boot
-
Flask service startup mode becomes app.run(debug=False) Copy the code
-
Start with Gunicorn
-
Worker 4 threads are 4 threads gunicorn -w 4 manage:app Copy the code
-
# when our app is built using factory functions gunicorn -w 4 "my_project:create_app()" Copy the code
-
-
-
Complete the above steps to start the Flask using Gunicorn
-
The supervisor section
-
The supervisor section
-
The main task is to complete the gunicorn configuration
-
Flask is started by gunicorn using four processes (four threads each)
-
[program:gunicorn] command=gunicorn -w 4 "manage:create_app()" -b :8091 directory=/home/a21036/waws/PaddleOCR priority=1 numprocs=1 autostart=true autorestart=true startretries=10 exitcodes=0 stopsignal=KILL stopwaitsecs=10 redirect_stderr=true [program:gunicorn_1] command=gunicorn -w 4 "manage:create_app()" -b :8092 directory=/home/a21036/waws/PaddleOCR priority=1 numprocs=1 autostart=true autorestart=true startretries=10 exitcodes=0 stopsignal=KILL stopwaitsecs=10 redirect_stderr=true [program:gunicorn_2] command=gunicorn -w 4 "manage:create_app()" -b :8093 directory=/home/a21036/waws/PaddleOCR priority=1 numprocs=1 autostart=true autorestart=true startretries=10 exitcodes=0 stopsignal=KILL stopwaitsecs=10 redirect_stderr=true [program:gunicorn_3] command=gunicorn -w 4 "manage:create_app()" -b :8094 directory=/home/a21036/waws/PaddleOCR priority=1 numprocs=1 autostart=true autorestart=true startretries=10 exitcodes=0 stopsignal=KILL stopwaitsecs=10 redirect_stderr=true Copy the code
-
Our Supervisor is started without being started using the following command
-
supervisord -c /usr/supervisor/supervisor.conf Copy the code
-
-
If we have started supervisor, we use the following command to start it
-
supervisorctl start gunicorn start gunicorn_1 start gunicorn_2 start gunicorn_3 Copy the code
-
supervisorctl start all Copy the code
-
-
-
Nginx part
-
Nginx part
-
The main consideration is the concurrency of the program, to start the four services, load balancing
-
In /etc/nginx/cond.d, create two new files. Upstream. conf controls the configuration of the actual monitoring port implementation of the distributed file backend.conf
-
upstream.conf
-
upstream backends { server localhost:9001; server localhost:9002; server localhost:9003; server localhost:9004; } server { listen 80; location / { proxy_pass http://backends; }}Copy the code
-
-
backend.conf
-
server { listen localhost:9001; location ^~ /static/ { alias /home/a21036/static/; autoindex on; } location = /upload { proxy_pass http://localhost:8091/upload; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location =/ { proxy_pass http://localhost:8091/; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen localhost:9002; location ^~ /static/ { alias /home/a21036/static/; autoindex on; } location = /upload { proxy_pass http://localhost:8092/upload; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location =/ { proxy_pass http://localhost:8092/; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen localhost:9003; location ^~ /static/ { alias /home/a21036/static/; autoindex on; } location = /upload { proxy_pass http://localhost:8093/upload; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location =/ { proxy_pass http://localhost:8093/; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen localhost:9004; location ^~ /static/ { alias /home/a21036/static/; autoindex on; } location = /upload { proxy_pass http://localhost:8094/upload; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location =/ { proxy_pass http://localhost:8094/; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}Copy the code
-
-
A serious mistake was made in this area:
-
server { listen localhost:8094; # Error source location ^~ /static/ { alias /home/a21036/static/; autoindex on; } location = /upload { proxy_pass http://localhost:8094/upload; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location =/ { proxy_pass http://localhost:8094/; proxy_redirect off; proxy_set_header Host $http_post; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}Copy the code
-
Actual error causes: We used Supervisor to start Gunicorn, and started the service of 8094. Then we used Nginx to listen to 8094, but the port was occupied. We need to use other ports to monitor 8094
-
-
-
-
Our nginx does not start with the following command
-
systemctl start nginx Copy the code
-
-
If we have started nginx, we use the following command to reload the configuration file
-
# Check our nginx configuration syntax for errors /usr/sbin/nginx -t Reload the configuration file /usr/sbin/nginx -s reload Copy the code
-
-
The other parts
-
Other:
-
When we have a problem with the configuration, we can use the specified log location in the configuration file to find the log, check the log can find the problem, the following uses nginx log as an example
-
# View method 1 tail -F xxxx.log # Newly generated logs are viewed in a scrolling mode # View method 2 vim xxxx.log View logs in full Copy the code
-
Nginx has two main logs placed in /var/log/nginx
- access.log
- error.log
- We can see that the previous configuration of port occupancy was incorrect
- access.log
-