nginx+uwsgi+flask 配置 HTTPS

Then connect the text, https://www.cnblogs.com/CooperXia-847550730/p/11526734.html paper to write a random picture API to deploy only a flask, very unstable,

Dead a few hours, so plan to deploy on the server nginx,

First, tell us about:

nginx is a web server for receiving a request to establish a connection, and the like forwarded to the backend

uwsgi is actually a web server, nginx but still not stable, burst handling is not as nginx, just to get here with uwsgi achieve nginx reverse proxy, flask is no way to directly nginx reverse proxy.

flask is a web framework to achieve site features

 

ok, next began to deploy, install nginx and uwsgi

yum install nginx

pip3 install uwsgi

On it

uwsgi method of eating:

uwsgi --socket 0.0.0.0:5000 --protocol=http -p 3 -w run:app

This can be started directly,

--socket 0.0.0.0:5000: Specifies the exposed port 5000.

--protocol=http: Http protocol instructions that port 5000 can be directly accessed using an HTTP request.

-p 3Indicating that the startup of the service occupies three processes.

-w run:app: -W specifies the module to start, run is the Project Initiation Document run.py remove the extension, app is run.py file variable app, namely Flask instance.

 

Then describes how to configure the startup file:

New uwsgi.ini file in the project directory,

content:

[uwsgi]
module = sprocess:app
master = true
processes = 3
chdir = ./
socket = ./project.sock
socket = 127.0.0.1:4000
logto = ./project.log
chmod-socket = 660
vacuum = true

Next start direct:

nohup uwsgi --ini uwsgi.ini > uwsgi.txt 2>&1 &

(Nohup command to start a background, you can directly install yum)

 

Next, configure nginx server,

vim /etc/nginx/nginx.conf,

content:

worker_processes 4;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;

server{
listen 80;
listen 443 ssl;
ssl_certificate /root/nginxproject/server.crt;
ssl_certificate_key /root/nginxproject/server.key;

location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:4000;
}

}
}

Which involves the crt and key certificates need to use openssl to generate, the article has been said,

If you do not remove the three rows on the line https

listen 443 ssl;
ssl_certificate /root/nginxproject/server.crt;
ssl_certificate_key /root/nginxproject/server.key;

 

 

Now you can visit! But Bo principal a mistake, but a lot of times, is always forget to aliyun where appropriate ports are open! ! ! ! ! !

I'm dead! It took more than an hour, or issue a certificate that is configured to be stupid to cry

 

 

Guess you like

Origin www.cnblogs.com/CooperXia-847550730/p/11537076.html
Recommended