Click on " Python crawler and data mining " above to follow
Reply to " Books " to receive a total of 10 e-books of Python from beginner to advanced
now
day
Chickens
soup
If you come from your hometown, you should know what happened in your hometown.
Introduction
Recently, a few friends asked how to configure https for the python programming website, plus the last time I took a list (write the api interface with flask), the other party also asked to configure the ssl encrypted https access method.
In order to answer and record these contents, the content of today's article is: deployment of Flask website + domain name access + free https certificate.
1. Deploy Flask website
I won't be lengthy here to introduce how Flask writes a website. I believe everyone who has read this article should have known Flask.
Go directly to the dry goods!
Python realizes online microblog data visualization . This is a flask website I programmed before. Let's take this directly to explain (the open source source code is provided, and you can mention it yourself)
Clone the source code
https://gitee.com/lyc96/weibo
Clone the source code to the local, you can see that the source code is probably the following
Launch website
The domain name and https need to be configured below, so here we use Alibaba Cloud server to deploy, first upload the source code to the server (with xftp)
Then start the flask website by command:
python3 weibo.py
This shows that the startup is successful, you can go directly to the browser to visit
(Here 192.168.1.109 is the Alibaba Cloud server's internal network ip, and external network access can directly access the public network. The public network ip is: 47.94.11.81)
Visit website
Enter the website in the browser: http://47.94.11.81:5000/, you can open the website
Now start to set up access via domain name!
Two, set up domain name access
The link visited above is: http://47.94.11.81:5000/, we can see that the port we set is 5000
Now you need to access through the domain name, for convenience, we change 5000 to 80, (the website defaults to port 80), and then restart the website (the way is the same as above)
The access method becomes (when the domain name is not configured)
http://47.94.11.81:80/ or http://47.94.11.81/
DNS
1. Domain name application
(This is very simple, you can go to Alibaba Cloud to apply for a domain name, and then you can file it), but I believe that most people who read this article have domain names.
2. Domain name resolution
Resolve the domain name to the corresponding server ip ( 47.94.11.81 )
Ok, so we have successfully configured the domain name ( lyc.chenlove.cn ) for the website !
Domain name access
Enter the website in the browser: http://lyc.chenlove.cn/, you can open the website
Ok, the Flask website can be accessed directly through the domain name.
Let’s start a prostitute with an ssl certificate (https) to give encrypted access to our website!
Three, https certificate
Start to teach you https certificate for white prostitution (free! Free! Free!)
The target of the white prostitution this time is the pagoda panel (a server management website). Today's focus is to obtain a free https certificate from this website! ! !
Apply for a certificate
###链接
https://www.bt.cn/admin/profe
1. Click on SSL management to apply for a certificate
2. Fill in the domain name (lyc.chenlove.cn)
3. Verify the server
Create a new folder and file in the red box on the server's website and directory, and fill in the corresponding content in the file. The result of successful verification is as follows:
Finally, download the https certificate to the local.
Configure nginx and https certificate
The installation and use of nginx are not introduced here (very simple, no more nonsense)
1. Upload the certificate to the server
After downloading the certificate and decompressing it
Because we are configuring nginx, now upload Nginx to the server
2. Configure nginx conf file
Create a new file ice-qjnubk-3000.conf in the /etc/nginx/conf.d ( default path of nginx ) directory
Edit ice-qjnubk-3000.conf
The red box is the content that needs to be modified (domain name, certificate location, and intranet forwarding link)
The intranet forwarding link here is http://192.168.1.109:9000, but here is changed to http://127.0.0.1:5000, so we also modify the intranet ip in the Flask website to 127.0.0.1, and the port is 5000
Then restart the website
3. Restart the nginx service
service nginx restart
After restarting nginx, the conf file we just wrote will take effect!
So our https is configured, super easy! ! !
https visit website
https://lyc.chenlove.cn
OK, the https certificate has been deployed successfully!
Four, summary
Dry goods today: deploy Flask website + domain name access + free https certificate, it has been successfully delivered to you!
In order for you to experience it, I will not close this website (https://lyc.chenlove.cn) for the time being! (In the beginning, it was to let everyone experience the actual combat process, using the domain name and server to demonstrate).
------------------- End -------------------
Recommendations of previous wonderful articles:
Solve the problem of generating large files in the C drive after installing Pycharm
An article teaches you to use Django to reversely generate models from an existing database
Teach you how to use Django to connect to Mysql
Welcome everyone to like , leave a message, forward, reprint, thank you for your company and support
If you want to join the Python learning group, please reply in the background [ Enter the group ]
Thousands of rivers and mountains are always in love, can you click [ Looking ]
/Today's message topic/
Just say a word or two~~