Tencent cloud server launched Django background project

As front-end engineers, with the continuous improvement of our technology, we are all thinking about how to make the webpage projects we write online, but the premise of this is to have our own server, and for the front-end projects that need to be online, we need a The background is used to obtain the data we need. Next, I will talk about how to use Tencent Cloud Server to upload the project written in the Django background (although it is not very common to use the background written in Django, but this is just to let yourself practice, you can try it )

1. Log in to your Tencent Cloud account and select a server to purchase

1.1 First, log in to the Tencent Cloud account and complete personal identity authentication

1.2 Choose a server that suits you

Here I take the lightweight server as an example,

1.3 After buying the server, a console option will appear in the upper right corner of your interface

Choose a lightweight server in cloud products, and then choose the server you bought

1.4 Reset server password

After entering the server, there will be an option to reset the password in the upper right corner of the server (it is recommended to reset the password after manually shutting down)

 After clicking Reset Password, a dialog box will appear

 Fill in according to the above options. If there is no manual shutdown, there will be an option to force shutdown after the setting is completed. Click Force shutdown, and your newly modified server password will take effect.

2. Configure Pagoda Linux image

First you need to download a software: Xshell, to perform related operations

XSHELL - NetSarang Website

After downloading Xshell, connect to the server

(1) Copy your public IP address (server side)

Note: I will not show you how to copy here

(2) Open xshell and connect to the server

Execute the new command, a dialog box will pop up

 (3) Set related operations

 

 After completing the above operations, click Connect, and if there is no problem with what you wrote, the following interface will appear

Search Pagoda Linux on the Internet, enter the official website, and download the Pagoda image 

Pagoda Panel - Simple and easy-to-use Linux/Windows server operation and maintenance management panel

Find the linux panel inside, use the script to install' (download the script shown in the picture: Centos)

Copy the above command into Xshell, press Enter after pasting, and install

After successful connection

If you are connecting for the first time, there will be an address of the internal network and the external network. If it is not the first time, then use

bt default

The following interface will appear

 Copy the external network address and open it in the browser

 Fill in the account and password in xshell, click Login

3. Online project

After entering the pagoda interface, there will be a pop-up window for automatic installation, select the first automatic installation, and then wait quietly....

3.1 Enter Tencent Cloud Server, liberate the port

Enter inside the server and find the firewall

 

 Click on the firewall to liberate the port (because you are uploading the django project, you need to use the database, so you need to liberate port 3306, and then liberate the port of your request address in the django project)

 As shown in the figure, the request address of my django is http://127.0.0.1:8889, so port 8889 needs to be liberated

After liberating the port, return to the pagoda interface

In security, liberate ports 3306 and 8889

 3.2 Import database file

Find your database, export it as sql, and then import it in the database in the pagoda

 Click to add database

 Fill in the database name (preferably the same as your local database name), fill in the user name (root cannot be used), and then define the password. After filling in, click Submit, and this database will appear in your pagoda database

 Then import your local .sql file, click Import

 Click Upload from local to import the content in your database

 After uploading the local file, click Import, if it shows success, then congratulations, the database import is successful

3.3 Upload background files

Click on the file option in the pagoda

 Find the wwwroot folder, upload your django background project, remember to upload the zip file, compress your ddjango project in advance, and then upload

 After the compressed package is uploaded to the pagoda, double-click the compressed package you uploaded to decompress it

Note: Before uploading the django project, remember to generate the requirements.txt file in the local project first

Generate the requirements command as follows:

pip freeze > requirements.txt

 Special attention: remember to change the ip address in your django project, because your database has been uploaded to the pagoda, so remember to change the ip address of the database in setting.py to your own public network ip or domain name, Also, the ip address that can access your own background also needs to be replaced, for example, replace http://127.0.0.1:8889 with http://(your own public network ip or domain name):8889

3.4 Start your own background project

Download the Python project manager in the software store. After the download and installation are complete, let it display on the home page

In this way, you can see the python project manager you downloaded on the home page

 Click on the python project manager to download python

 Click version management to download the python version you need. I use python3.9, so I downloaded 3.9.7 (download according to the requirements of personal projects, it is best to download the same version as the python in your computer. )

back to project management

Click to add item

 Enter the project name (preferably the same name as your background, no special format requirements), then select the startup path (that is, the background project uploaded in the previous step), select the python version, select django for the framework, and select uwsgi for the startup method , the startup file is the wsgi file in your project, the port number fills in the port number of your background (for example, 8889), other options are default

After filling these, click OK, and then start

4. Upload the front-end web project

Click on the site in the pagoda

 Then click Add Site

Then fill in the domain name or public network ip (that is, which URL do you want to get the content of your webpage through, but it is best to buy the domain name in advance to make the URL of your webpage more beautiful)

 Then click Submit. After the submission is successful, it will display the running

Then go back to the file option, and you will find that there will be an extra folder under the wwwroot folder that is the same as your domain name or public network ip name.

 Then package your front-end files locally. Since I use the front-end written by vue scaffolding, use

npm run build

This line of command is packaged, and then a dist folder will be generated in your root directory, and your dist folder will be compressed

 Then go to your pagoda to find the folder just now, delete everything in it, and upload the compressed package of your dist

 After the upload is successful, decompress your dist compressed package. After decompressing successfully, cut all the files and folders in the dist to the folder created by the website just now (same level as the dist compressed package)

 Note: Remember to modify the address of your front-end request back-end before compression, and replace it with the back-end address you set in the pagoda

After completing the above steps, the django background project and the launch have been completed

Guess you like

Origin blog.csdn.net/m0_52578688/article/details/124478219