From buying a domain name to nginx, flask build your own website

                             Build a website that belongs only to you?


1. Register domain name (optional*)

1. Register an Alibaba Cloud account

Website: Login (register)

2. Purchase a domain name : Alibaba Cloud domain name registration

One yuan domain name, free domain name, etc.
An information template needs to be created during the purchase process (you must complete the email authenticity verification template before you can purchase the domain name. There is a hyperlink in the domain name purchase process that you can click to fill in).
After buying a server, student authentication is required (you need to log in to Xuexin.com. After authentication, you can purchase a server at a discount, or you can buy a server from other websites)

payment successful

3. Domain name view

Support Alipay payment . After the payment is successful, click the domain name console, you can see the domain name you just bought.

Second, buy a server

Student certification and purchase :

The server is a remote system that is always on . It is divided into four types: windows, Linux, Unix, and NetWare. Generally, Linux is efficient but requires some basic Linux foundation, so Mengxin recommends to practice with Windows first. Address: Alibaba Cloud Cloud Wing Plan (requires login/register for Alibaba Cloud account and student authentication-Xuexin.com)
Buy server

Three, set up a security group

1. Enter the security group

Go to Alibaba Cloud Personal Center, check your own server, click Network and Security, click Security Group, and configure rules.

          Click on Security GroupInsert picture description here

2. Configuration options (corresponding in direction and out direction):Insert picture description here


Four, domain name resolution

1. Copy the public IP :

Return to the server list and copy the server’s public IP (IP open to the entire world)Copy server public IP

2. Click on domain name resolution :

Enter the domain name console from the Alibaba Cloud personal center , or click the Alibaba Cloud icon, click the opened project, click the domain name, and then find your own domain name for resolution.
Insert picture description hereClick to resolve

3. Resolve to the server :

Description :
The DNS (address points) to your server public IP , so that when people visit your domain name in the address bar, the domain name is resolved to this server IP, will be able to access the server (the ultimate goal is to visit To the server, so you can directly enter the server's public network IP in the address bar. This is also the reason why the registered domain name is optional, but the domain name is more personalized and easy to remember)Details

Five, install the necessary software on the server

(Here is nginx + flask + python to build)

1. Log in to your own server (remote computer, Windows version) :

  • Start via Alibaba Cloud server (web version)

  • Using the computer's own Remote Desktop Connection feature

  • Other remote login software

    Search bar → remote desktop connection → input server public network IP (password) → connection is successful

2. Install server software and necessary software :

At least one server monitoring software needs to be installed here, two are installed here: nginx, flask, and a programming language Anaconda package (Anaconda includes python, or install python directly) and the programming environment pycharm (with flask).
Baidu network disk address : web building tool
extraction code : dfjf


brief description :

  • The nginx server is used to monitor the domain name (or IP) and port number (configurable), and make corresponding operations (point to a web page → handle it yourself, or point to the address and port number monitored by another server → do not do the final processing, As an agent).
  • The flask server is also listening to a certain address and port (default 5000, all configurable), pointing to its own project (own main page)
  • Process : Use the pycharm compiler and flask framework to build your own web page and save it to the server (computer). When someone visits your domain name (server public network IP), the domain name is resolved to the server public network IP address, and the command is accessed The server (computer), which is monitored by the nginx server, performs an operation to forward the address to a new address that can be monitored by the flask server. The flask server listens to the instruction, points the address to the local webpage address, and returns the content to the browser for access .

Six, specific operations to achieve hello son! :

A、nginx:

1. Turn off the server firewall

The firewall of the server must be turned off, otherwise it may not be accessible .
Search "Firewall and Network Protection" in the taskbar, and close all firewalls after opening the window (Is there any other way to not turn off?)
Insert picture description here

2. Open the nginx configuration file

After everything is installed, unzip nginx, open the conf folder in the nginx folder directory, and open nginx in notepad
Insert picture description here

3. Configure nginx server

?At port 80, add: proxy_pass http://127.0.0.1:5000; ❗The semicolon and spaces cannot be less.
And annotate the next line with #, and add the address whose listening IP is localhost and port number is 80.
When the computer (localhost) receives the request with port number 80, it forwards the request to the server listening on port 5000 of 127.0.0.1. Addresses beginning with http:// default to port 80. Addresses beginning with https:// default to port 443. Insert picture description here


? Make the following modifications on port 443 (the last line), without writing the certificate line first.
Insert picture description here

4. Start and close nginx

?You need to be in the home directory of nginx when you start, and enter cmd here to start
Insert picture description here


? Enter nginx.exe to start. If no error is reported, the startup is successful. If an error is reported, check whether the newly modified nginx configuration file is wrong.
Insert picture description here


? Close input nginx.exe -s stop, you need to re-open a cmd in this directory, you can also open the task manager to close (you must first close the child process-lower)
Insert picture description here

B、flask:

1. Open pycharm and create a new flask project

Insert picture description here

2. Simple modification

After creating a new flask project, the following interface is automatically generated and simple modifications are made:
Insert picture description here

3. Run flask

Right-click app.py and select Run to see this interface: So
Insert picture description here
far, the flask framework has been built, and the server has been started, listening to port 5000. When any computer or mobile phone (you need to add m when configuring the server security group) access your domain name, it will appear:Insert picture description here

4. Run app.py directly without opening pycharm

⚪You need to configure the python environment variable for the first time.
Search in the taskbar for'Edit System Environment Variables' → Environment Variables → Find Path Edit → Paste the python installation path at the top and add an English semicolon';'
Insert picture description here
Insert picture description here
Insert picture description here


⚪Check the project path and
find no app The .py location can be found like this
Insert picture description here


⚪Enter cmd under the address bar of this folder, and enter python app.py to start the service directly without opening pycharm to take up memory. Is the
first website finally built?

Seven, domain name SSL certificate purchase, download, configuration (optional*)

1. Purchase

Alibaba Cloud domain name SSL certificate purchase


2. Application

After purchase, enter the certificate console and apply for a certificate
Insert picture description here
Insert picture description here
Insert picture description here

3. Download and unzip

Download the certificate after the verification is successful. The server type is nginx. Save it where you can find it, preferably in the nginx file directory.
Then open the compressed package and unzip it to the conf folder directory

4. Configure nginx file

There is an nginx file in the conf directory, open it with Notepad, and add the following certificate verification on port 80 and port 443 (only 443 is given):
Insert picture description here

5. View the effect

Insert picture description here

?Not ssl certified:
Insert picture description here


8. Domain name registration (optional*)

  • To prevent you from doing bad things with a domain name, so domain names more than three months old must be filed, otherwise you cannot access your server through the domain name. You need to use a server more than three months to file the domain name. One server can file multiple records at the same time A domain name, the specific number depends on the description of the specific server.

  • This step is not only cumbersome but also takes a long time, so you must be patient. During this period, you need to use ID card to take photos, fill in information, recognize face recognition, download nail recognition, phone recognition... wait within 20 days...

  • Alibaba Cloud filing link

Guess you like

Origin blog.csdn.net/GeniusXYT/article/details/100106204