How to use Flash + nginx to build?

Time:2022-1-6

Check whether the port number is occupied

netstat -anp | grep 8080
Click and drag to move
View the progress of the application

ps aux|grep nginx
Click and drag to move
Flash part
First, skip the service part written by flash (related to business)

Gunicorn section
Firstly, the startup method of our flash project is:

app.run(host=”0.0.0.0″,use_reloader=True, port=5000)
Click and drag to move
If we use gunicorn for startup, we don’t need to write the port number. We can use gunicorn to set the startup port number

The startup mode of flash service becomes

app.run(debug=False)
Click and drag to move
Starting with gunicorn

The original command worker thread is 4

gunicorn -w 4 manage:app
Click and drag to move

When our app is built using factory functions

gunicorn -w 4 “my_project:create_app()”
Click and drag to move
After completing the above steps, you can use gunicorn to start flash

Supervisor section
It mainly completes the configuration of gunicorn

We use four processes (four threads per process) to start flash through gunicorn

[program:gunicorn]
command=gunicorn -w 4 “manage:create_app()” -b :8091
directory=/home/a21036/waws
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/
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/
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/
numprocs=1
autostart=true
autorestart=true
startretries=10
exitcodes=0
stopsignal=KILL
stopwaitsecs=10
redirect_stderr=true
Click and drag to move
If our supervisor is not started, use the following command to start it

supervisord -c /usr/supervisor/supervisor.conf
Click and drag to move
If we have already started supervisor, we use following command to start it

supervisorctl
start gunicorn
start gunicorn_1
start gunicorn_2
start gunicorn_3
Click and drag to move
supervisorctl
start all
Click and drag to move
Nginx section
Mainly considering the concurrency of the program, load balance the four services started

In / etc / nginx / cond New in DWebpage GameTwo files, upstream Conf controls the distributed file backend Conf actual listening port to realize operation configuration

upstream.conf

upstream backends {

 server localhost:9001;
 server localhost:9002;
 server localhost:9003;
 server localhost:9004;

}
server {

 listen 80;
 location / {
 proxy_pass 

} }
Click and drag to move
backend.conf

server {

 listen localhost:9001;
 location ^~ /static/ {
    alias /home/a21036/static/;
    autoindex on;
 }
 location = /upload {
    proxy_pass 
    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 
     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 
    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 
     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 
    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 
     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 
    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 
     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;
 }

}
Click and drag to move
A serious mistake was made in this place:

server {

listen localhost:8094;   #  Error source
 location ^~ /static/ {
    alias /home/a21036/static/;
    autoindex on;
 }
 location = /upload {
    proxy_pass 
    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 
     proxy_redirect off;
     proxy_set_header Host www.sangpi.com$http_post;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

}
Click and drag to move
Actual error reason: we use supervisor to start gunicorn and start the service of 8094. Then we use nginx to listen to 8094. The port will be occupied. I have that we need to use other ports to listen to 8094. Here, we use 9004 to monitor 8094

If our nginx is not started, use the following command to start it

systemctl start nginx
Click and drag to move
If we have started nginx, we use following command to reload configuration file

Check whether there is a problem with our nginx configuration syntax

/usr/sbin/nginx -t

Reload profile

/usr/sbin/nginx -s reload
Click and drag to move
Other parts
When we have a problem with the configuration, we can find the log through the location of the log specified in the configuration file and check the log to find the problem. The following takes nginx log as an example

View method 1

tail -F xxxx. Log # the newly generated log is viewed by scrolling

View mode 2

vim xxxx. Log # full view log
Click and drag to move
Nginx has two main logs in / var / log / nginx

Recommended Today

Redis Client On Error: Error: write ECONNABORTED Config right

Solve the redis client on error: error: write econnaborted config rightwe Problem Description: Solution: 1. First, check whether the firewall of Linux is turned on Turn off the firewall [[email protected]]# systemctl stop firewalld.service Open 6379 port number [[email protected]]# sudo firewall-cmd –zone=public –add-port=6379/tcp –permanent success [[email protected]]# sudo firewall-cmd –reload success 2. Check whether the redis startup […]